I am trying make use of Mehdi El Gueddari's DBContextScope solution and DI it into my WebAPI2 Controller as follows:
NinjectConfigurator.cs:
container.Bind<IUserProfileInquiryProcessor>().To<UserProfileInquiryProcessor>().InRequestScope();
container.Bind<IDbContextScopeFactory>().To<DbContextScopeFactory>().InSingletonScope();
UserProfileController.cs:
public UserProfileController(
IUserProfileInquiryProcessor userProfileInquiryProcessor,
IDbContextScopeFactory dbContextScopeFactory)
{
_dbContextScopeFactory = dbContextScopeFactory;
_userProfileInquiryProcessor = userProfileInquiryProcessor;
}
However, Ninject appears to be failing to inject IDbContextScopeFactory
and returns with the following exception:
An error occurred when trying to create a controller of type 'UserProfileController'. Make sure that the controller has a parameterless public constructor.
I know it is IDbContextScopeFactory
that is failing to resolve and the controller is created if I omit that parameter (only) from the constructor.
Can anyone advise what I am doing wrong or what I should try? Thanks.