I'm trying to figure out a way to inject dependencies into my AuthorizeAttribute
in SignalR similar to the way it is done in WebAPI.
In Web API I know I can call builder.RegisterWebApiFilterProvider(config);
but I can't quite seem to find an equivalent for SignalR. The closest thing I can find that looks like it might do the trick is the PropertiesAutowired()
method.
I have tried builder.RegisterType<MyAuthorizationAttribute>.PropertiesAutowired();
where my attribute looks like
public class MyAuthorizationAttribute : AuthorizeAttribute
{
public IRepository Repository { get; set; }
public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor,
IRequest request)
{
Repository.QueryStoredProcedure("Test");
...
}
protected override bool UserAuthorized(IPrincipal user)
{
...
}
}
But the instance of Repository
is null every time.