C# 将类的实例传递给属性
我的web api身份验证有一个属性:C# 将类的实例传递给属性,c#,asp.net-mvc,attributes,asp.net-web-api,C#,Asp.net Mvc,Attributes,Asp.net Web Api,我的web api身份验证有一个属性: public class ApiAuthenticationAttribute : ActionFilterAttribute { private IApiAuthentication AuthenticationProvider { get; set; } public ApiAuthorizeAttribute(Type apiAuthorizationType) { AuthenticationProvide
public class ApiAuthenticationAttribute : ActionFilterAttribute
{
private IApiAuthentication AuthenticationProvider { get; set; }
public ApiAuthorizeAttribute(Type apiAuthorizationType)
{
AuthenticationProvider = (IApiAuthentication)Activator.CreateInstance(apiAuthorizationType);
}
....
}
在这个属性中,我有一个执行身份验证逻辑的IApiAuthentication
类型
对于将具体类型的IApiAuthentication
传递给我在type
中传递的属性,如下所示:
[ApiAuthentication(typeof(ApiAuthentication))]
我想知道有没有更好的办法