Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nhibernate/nhibernate.aspnetcore.identity

ASP.NET Core Identity Provider for NHibernate
https://github.com/nhibernate/nhibernate.aspnetcore.identity

aspnetcore identity-provider mssql mysql nhibernate postgresql sqlite

Last synced: 5 days ago
JSON representation

ASP.NET Core Identity Provider for NHibernate

Awesome Lists containing this project

README

        

# NHibernate.AspNetCore.Identity

ASP.NET Core Identity Provider implemented with NHibernate

![ASP.NET Core Identity with nhibernate](https://raw.github.com/nhibernate/NHibernate.AspNetCore.Identity/master/database/identity-nh.svg)

![Database diagram](https://raw.github.com/nhibernate/NHibernate.AspNetCore.Identity/master/database/db_schema.png)

Nuget package:

- [NHibernate.AspNetCore.Identity](https://www.nuget.org/packages/NHibernate.AspNetCore.Identity/)

## About Version

- 8.0.x is compatible with .Net 8.0.x;
- 7.0.x is compatible with .Net 7.0.x;
- 6.0.x is compatible with .Net 6.0.x;
- 5.0.x is compatible with .Net 5.0.x;
- 3.1.x is compatible with .Net Core 3.1.x;
- 3.0.x is compatible with .Net Core 3.0.x;

## Usage

### 1. Create a Asp.Net Core Mvc Project with identity support

```sh
dotnet new mvc --auth Individual
```

### 2. Add reference to `NHibernate.AspNetCore.Identity` and `NHibernate.NetCore`

```sh
dotnet add package NHibernate.AspNetCore.Identity
dotnet add package NHibernate.NetCore
```

> `NHibernate` will be installed automatically.

### 3. Setup database

- Use the sql scripts in `database` folder to create aspnet identity related tables, only support postgresql, mssql and mysql now;

> If you want other database support, please let me know, any issue, pull request is welcome!

- Config NHibernate to use your database;

### 4. Change `Startup.cs` to use database and nhibernate

```cs
public class Startup {

public void ConfigureServices(
IServiceCollection services
) {
// Remove EFCore stores.
// services.AddDbContext(
// options =>
// options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
// services.AddDefaultIdentity()
// .AddEntityFrameworkStores();

// Add Hibernate stores
var cfg = new Configuration();
var file = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"hibernate.config"
);
cfg.Configure(file);
// Add identity mapping based on dialect config (dialet must contains
// PostgreSQL, MySQL, MsSql or Sqlite)
cfg.AddIdentityMappings();
// using default xml mapping.
cfg.AddAssembly(typeof(Startup).Assembly);
// using `NHibernate.Mapping.ByCode`, please comment the line above,
// and uncomment line flowing lines;
// var modelMapper = new NHibernate.Mapping.ByCode.ModelMapper();
// modelMapper.AddMapping();
// modelMapper.AddMapping();
// modelMapper.AddMapping();
// var mappings = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
// cfg.AddMapping(mappings);

services.AddHibernate(cfg);
services.AddDefaultIdentity()
.AddRoles()
.AddHibernateStores();

}
}
```

> Note: When using with SqlServer, you need add `System.Data.SqlClient` package to your project.

For more detailed samples, please look at the [WebTest](https://github.com/nhibernate/NHibernate.AspNetCore.Identity/tree/master/test/WebTest) project.

## Credits

Special thanks to the following individuals, organisations and projects whose work is so important to the success of NHibernate (in no particular order):

- [NUnit](https://nunit.org/) - unit testing;
- [JetBrains](https://www.jetbrains.com/?from=NHibernate.AspNetCore.Identity) - open source license;