Dynamically adding attributes in ServiceStack

此生再无相见时 提交于 2019-12-24 05:53:11

问题


I'm attempting to add a "Restrict" attribute in my AppHost. Here is my code:

var restrictAttribute = new RestrictAttribute { ExternalOnly = true };
foreach (var dto in dtos)
{
    dto .AddAttributes(restrictAttribute);
}

The DTOs I'm adding them to are ones specifically for POST requests.

The problem I'm facing is that after adding the attributes dynamically, the ServiceStack functionality for the restrict doesn't work. It DOES add the attribute, but doesn't actually restrict anything.

The only way I can make this work is by adding the Restrict Attribute in the Request DTO manually. Am I doing something wrong here?


回答1:


For dynamically adding Service Attributes you need to add them before AppHost.Configure() since they're already initialized by the time Configure() is run, so they need to be either added in AppHost constructor or before AppHost.Init() is called.



来源:https://stackoverflow.com/questions/36403300/dynamically-adding-attributes-in-servicestack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!