GithubHelp home page GithubHelp logo

nhibernate.aspnetcore.identity's Introduction

NHibernate.AspNetCore.Identity

ASP.NET Core 2.0 Identity provider that uses NHibernate for storage

Purpose

ASP.NET Core 2.0 shipped with yet another rewrite of the Identity system (in the Microsoft.AspNetCore.Identity package) in order to support both local login and remote logins via OpenID/OAuth, but only ships with an Entity Framework provider (Microsoft.AspNetCore.Identity.EntityFrameworkCore). The changes were significant enough to require another project since NHibernate.AspNet.Identity is incompatible with the new classes.

Features

  • Drop-in replacement ASP.NET Core 2.0 Identity with NHibernate for persistence.
  • Based on same schema required by Microsoft.AspNetCore.Identity.EntityFrameworkCore for model compatibility.
  • Contains the same IdentityUser class used by the EntityFramework provider in the EntityFrameworkCore project.
  • Supports additional profile properties on your application's user model.
  • Provides UserStore<TUser> implementation that implements the same interfaces as the EntityFramework version:
    • IUserStore<TUser>
    • IUserLoginStore<TUser>
    • IUserRoleStore<TUser>
    • IUserClaimStore<TUser>
    • IUserLoginStore<TUser>
    • IUserPasswordStore<TUser>
    • IUserSecurityStampStore<TUser>

Quick-start guide

These instructions assume you know how to set up NHibernate within an MVC application.

  1. Create a new ASP.NET Core 2.0 project, choosing the Individual User Accounts authentication type.
  2. Remove the Entity Framework packages and replace with NHibernate Identity:
Uninstall-Package Microsoft.AspNetCore.Identity.EntityFrameworkCore
Uninstall-Package EntityFramework
Install-Package NHibernate.AspNetCore.Identity
  1. In ~/Models/IdentityModels.cs: a. Remove the namespace: Microsoft.AspNetCore.Identity.EntityFrameworkCore a. Add the namespace: NHibernate.AspNetCore.Identity a. Remove the ApplicationDbContext and ApplicationUserContext classes completely.
  2. In ~/Controllers/AccountController.cs a. Remove the namespace: Microsoft.AspNetCore.Identity.EntityFrameworkCore a. 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.
  3. 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);

Thanks To

Special thanks to Antônio Milesi Bastos whos NHibernate.AspNet.Identity project gave me the base for jumpstarting the NHibernate ASP.NET Core 2.0 provider

nhibernate.aspnetcore.identity's People

Contributors

codekaizen avatar mesbahamin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

devalot76 kongcon

nhibernate.aspnetcore.identity's Issues

Nuget package not published

Hello,

First off thanks for this awesome piece of work. However the documentation states the nuget package is available but apparently it's not? Any chances to have it released?

Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.