Using ServiceStack's Autoquery I have a simple Request DTO defined (example below). I would like to swap templates (Layouts) to use a different Razor layout (as per the SS templates swap documentation here)?
Example of Request DTO:
Route("/customers", "GET")]
public class QueryCustomers : QueryDb<FindFilesResponse>
{
}
Example of Layouts: _Layout.cshtml and _PrintFriendly.cshtml templates
For above query I would like to swap layouts at the client level.
All the ClientCanSwapTemplatesAttribute does is populate the
IRequest.Itemsdictionary from the HTTP Request params:So you could choose to do this in a Request Filter, e.g:
Alternatively in order to be able to use Filter Attributes on AutoQuery Services since they're implementation is auto-generated is to create a Custom AutoQuery implementation, e.g:
Whilst Filter attributes would also work when annotated on the Request DTO, i,e:
They're usage is discouraged because they would add dependencies to your Service Model. But another solution could be to add Attributes dynamically in your AppHost constructor, e,g: