https://github.com/nhibernate/nhibernate.aspnet.identity
ASP.NET Identity Provider for NHibernate
https://github.com/nhibernate/nhibernate.aspnet.identity
Last synced: 5 months ago
JSON representation
ASP.NET Identity Provider for NHibernate
- Host: GitHub
- URL: https://github.com/nhibernate/nhibernate.aspnet.identity
- Owner: nhibernate
- License: mit
- Created: 2013-11-03T16:53:53.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2018-10-17T05:03:12.000Z (about 7 years ago)
- Last Synced: 2025-04-23T04:44:35.594Z (8 months ago)
- Language: C#
- Homepage: http://nhibernate.info/NHibernate.AspNet.Identity/
- Size: 1.84 MB
- Stars: 111
- Watchers: 32
- Forks: 49
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://ci.appveyor.com/project/milesibastos/nhibernate-aspnet-identity)
[](http://waffle.io/nhibernate/NHibernate.AspNet.Identity)
NHibernate.AspNet.Identity
=======================
ASP.NET Identity provider that uses NHibernate for storage
[](https://waffle.io/nhibernate/NHibernate.AspNet.Identity/metrics)
## About this ##
[](http://youtu.be/pb4QgjXkT7E)
## Purpose ##
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).
## Features ##
* Drop-in replacement ASP.NET Identity with NHibernate as the backing store.
* Based on same schema required by EntityFramework for compatibility model
* Contains the same IdentityUser class used by the EntityFramework provider in the MVC 5 project template.
* Supports additional profile properties on your application's user model.
* Provides UserStore implementation that implements the same interfaces as the EntityFramework version:
* IUserStore
* IUserLoginStore
* IUserRoleStore
* IUserClaimStore
* IUserPasswordStore
* IUserSecurityStampStore
## Quick-start guide ##
These instructions assume you know how to set up NHibernate within an MVC application.
1. Create a new ASP.NET MVC 5 project, choosing the Individual User Accounts authentication type.
2. Remove the Entity Framework packages and replace with NHibernate Identity:
```PowerShell
Uninstall-Package Microsoft.AspNet.Identity.EntityFramework
Uninstall-Package EntityFramework
Install-Package NHibernate.AspNet.Identity
```
3. In ~/Models/IdentityModels.cs:
* Remove the namespace: Microsoft.AspNet.Identity.EntityFramework
* Add the namespace: NHibernate.AspNet.Identity
* Remove the ApplicationDbContext class completely.
4. In ~/Controllers/AccountController.cs
* Remove the namespace: Microsoft.AspNet.Identity.EntityFramework
* Add the relevant ISession implementation that will be used by default. This could be from a DI implementation.
Note: This isn't mandatory, if you are using a framework that will inject the dependency, you shouldn't need the parameterless constructor.
5. Setup configuration code
NHibernate
```C#
// 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(
new UserStore(session);
```
FluentNHibernate
```C#
// 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(
new UserStore(session);
```
## Thanks To ##
Special thanks to [David Boike](https://github.com/DavidBoike) whos [RavenDB AspNet Identity](https://github.com/ILMServices/RavenDB.AspNet.Identity) project gave me the base for jumpstarting the NHibernate provider