I use OWIN + Microsoft.AspNet.Identity.Owin (v.2.0.0.0) in Web application. I register UserManager/DbContext per web request, as widely recommended:
app.Crea
You can put the logic for disposing the instances you create with CreatePeOwinContext()
in the same callback you use to create this intances.
That is:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.CreatePerOwinContext(ClassIWantOneInstancePerContext.Create);
//other code...
}
}
Then you only should care about to include a call to DisposeOnPipelineCompleted()
within the callback used to instantiate your class. That is:
public class ClassIWantOneInstancePerContext
{
//other code...
public static ClassIWantOneInstancePerContext Create()
{
ClassIWantOneInstancePerContext TheInstance = new ClassIWantOneInstancePerContext();
HttpContext.Current.DisposeOnPipelineCompleted(TheInstance);
return TheInstance;
}
}
Also don't forget to include the Dispose()
method on your class definition!