ASP.NET Identity providers that use NHibernate
ASP.NET Identity provider that users NHibernate for storage
ASP.NET MVC 5 shipped with a new Identity system (in the Microsoft.AspNet.Identity.Core package) in order to support both local login and remote logins via OpenID/OAuth, but only ships with an Entity Framework provider (Microsoft.AspNet.Identity.EntityFramework).
These instructions assume you know how to set up NHibernate within an MVC application.
Uninstall-Package Microsoft.AspNet.Identity.EntityFramework
Uninstall-Package EntityFramework
Install-Package NHibernate.AspNet.Identity
In ~/Controllers/AccountController.cs
Setup configuration code
NHibernate
// this assumes you are using the default Identity model of "ApplicationUser"
var myEntities = new [] {
typeof(ApplicationUser)
};
var configuration = new Configuration();
configuration.Configure("sqlite-nhibernate-config.xml");
configuration.AddDeserializedMapping(MappingHelper.GetIdentityMappings(myEntities), null);
var factory = configuration.BuildSessionFactory();
var session = factory.OpenSession();
var userManager = new UserManager<ApplicationUser>(
new UserStore<ApplicationUser>(session);
FluentNHibernate
// this assumes you are using the default Identity model of "ApplicationUser"
var myEntities = new [] {
typeof(ApplicationUser)
};
var configuration = Fluently.Configure()
.Database(/*.....*/)
.ExposeConfiguration(cfg => {
cfg.AddDeserializedMapping(MappingHelper.GetIdentityMappings(myEntities), null);
});
var factory = configuration.BuildSessionFactory();
var session = factory.OpenSession();
var userManager = new UserManager<ApplicationUser>(
new UserStore<ApplicationUser>(session);
Special thanks to David Boike whos RavenDB AspNet Identity project gave me the base for jumpstarting the NHibernate provider