Reputation: 3051
I've an action filter attribute which has a property that needs to be injected by AutoFac. Because it is an action filter attribute i can't use constructor injection.
Property:
private readonly ISocialAppUnitOfWork _socialAppUnitOfWork;
Resolve:
public SecurityActionFilter()
{
_socialAppUnitOfWork = DependencyResolver.Current.GetService <ISocialAppUnitOfWork>();
}
Config:
builder.RegisterType<SecurityActionFilter>().InstancePerHttpRequest();
DependencyResolver.SetResolver(new AutofacDependencyResolver(builder.Build()));
After getting the service in the constructor the _socialAppUnitOfWork property remains null.
Why isn't it resolving my dependency?
Upvotes: 1
Views: 1322
Reputation: 3051
This did the trick:
// Set this action filter for every controller and inject interface
builder.Register(c => new SecurityActionFilter(c.Resolve<ISocialAppUnitOfWork>()))
.AsActionFilterFor<Controller>().InstancePerHttpRequest();
// Register all the action filters
builder.RegisterFilterProvider();
Upvotes: 1
Reputation: 1195
Try using: builder.RegisterType().As().InstancePerHttpRequest();
Upvotes: 0