Fredrick Lackey - 242 - Aug 14, 2014

What’s the best way to clear the Id in the DTO before sending it back to the client?  Need to do this for every request.

Have them share an interface like IHasIntId and use a typed response filter, e.g:

RegisterTypedResponseFilter<IHasIntId>((req, res, dto) => dto.Id = 0);

see: https://github.com/ServiceStack/ServiceStack/wiki/Request-and-response-filters#typed-request-filters

Fredrick Lackey:

What am I missing?  I’ve added the interface to the DTO and the filter in the Configure.  It is never applied:

this.RegisterTypedResponseFilter<IClearId<long>>((req, res, dto) =>
{
    dto.Id = 0;
    //res.EndRequest();
});

Make it a concrete interface like IClearLongId.

Fredrick Lackey:

Tried that. Actually had both examples in my reply but cleared it out to save space.

I’ve just added a example in this commit: https://github.com/ServiceStack/ServiceStack/commit/d97f1160ec669f3b2d7c160169a07bffac8add76 - and it’s working as expected. If you can’t find why your’s is different can you post the full Service impl and registration code to: https://github.com/ServiceStack/Issues

Jeff Gabhart:

How about not including Id on the dto?