Skip to content

robocik/NHibernate.AspNet.Identity

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NHibernate.AspNet.Identity

ASP.NET Identity provider that users NHibernate for storage

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 requirede 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

Instructions

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:
Uninstall-Package Microsoft.AspNet.Identity.EntityFramework
Uninstall-Package EntityFramework
Install-Package NHibernate.AspNet.Identity
  1. In ~/Models/IdentityModels.cs:
    • Remove the namespace: Microsoft.AspNet.Identity.EntityFramework
    • Add the namespace: NHibernate.AspNet.Identity
    • Remove the ApplicationDbContext class completely.
  2. In ~/Controllers/AccountController.cs
    • Remove the namespace: Microsoft.AspNet.Identity.EntityFramework
    • Add the connection string name to the constructor of the UserStore. Or empty constructor will use DefaultConnection
    var mapper = new ModelMapper();
    mapper.AddMapping<IdentityUserMap>();
    mapper.AddMapping<IdentityRoleMap>();
    mapper.AddMapping<IdentityUserClaimMap>();
    mapper.AddMapping<IdentityUserLoginMap>();

    var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

    var configuration = new Configuration();
    configuration.Configure("sqlite-nhibernate-config.xml");
    configuration.AddDeserializedMapping(mapping, null);

    var factory = configuration.BuildSessionFactory();
    var session = factory.OpenSession();

    var userManager = new UserManager<ApplicationUser>(
        new UserStore<ApplicationUser>(session);

Thanks To

Special thanks to David Boike whos RavenDB AspNet Identity project gave me the base for jumpstarting the NHibernate provider

About

ASP.NET Identity providers that use NHibernate

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 70.2%
  • C# 29.5%
  • Other 0.3%