I am implementing an NHibernate Session Factory in a WebAPI 2 project that uses OWIN. Below is a snippet of my startup class. I notice that the Startup is being called each time I load a page in my debug environment. This seems very expensive and SessionFactory should only be created once per application lifetime.
How do I avoid this? I think the repeated calls is causing problems. I am getting errors that seem related to the session factory being created multiple times within OWIN.
Public Class Startup
Public Sub Configuration(app As IAppBuilder)
GlobalConfiguration.Configure(AddressOf WebApiConfig.Register)
app.CreatePerOwinContext(AddressOf MobLib.MobDataProvider.CreateProvider)
End Sub
End Class
Update
I've confirmed that Configuration
is only running once, but calls to CreateProvider
are occurring every time the page loads. Is this by design?