Dynamically adding attributes in ServiceStack

2019-08-13 19:01发布

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条回答
地球回转人心会变
2楼-- · 2019-08-13 19:52

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.

查看更多
登录 后发表回答