I'd like to use Ninject to inject my DbContext ASP.NET Identity Framework.
At the moment I have the following line in my web.config file:
<appSettings>
<add key="owin:appStartup" value="OwinTest.Identity.OwinStart, OwinTest.Identity" />
</appSettings>
This causes the Configuration() method on class OwinStart in my OwinTest.Identity project to be called.
Here's my OwinStart class:
public class OwinStart
{
public void Configuration(IAppBuilder app)
{
app.CreatePerOwinContext<IMyContext>(this.GetDbContext);
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.UseCookieAuthentication(
new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login")
});
}
/// <summary>
/// Gets an instance of the DbContext for OWIN
/// </summary>
/// <returns></returns>
private IMyContext GetDbContext()
{
// Create dbcontext instance
return new MyContext();
}
}
As you can see, I create an instance of my DbContext using the new keyword, when I really want to be making use of Ninject to inject my DbContext in.
Is it possible for me to wire up Ninject to inject my database context in within OWIN?
news up a DbContext.