Skip to content

rms81/IdentityServer3.Contrib.Nhibernate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build status ![NuGet Pre Release](https://img.shields.io/nuget/vpre/IdentityServer3.Contrib.Nhibernate.svg?maxAge= reStructuredText 2592000?style=plastic)

Nhibernate Persistence Layer for IdentityServer3

Just use the extension method RegisterNhibernateStores with an Nhibernate Session Factory:

var factory = new IdentityServerServiceFactory();
factory.RegisterNhibernateStores(new NhibernateServiceOptions(nhSessionFactory)
{
   RegisterOperationalServices = true,
   RegisterConfigurationServices = true
});

A way of getting the SessionFactory. Use MappingHelper.GetNhibernateServicesMappings() to get the mappings.

private static ISessionFactory GetNHibernateSessionFactory()
{
   var connString = ConfigurationManager.ConnectionStrings["IdSvr3Config"];

   var sessionFactory = Fluently.Configure()
       .Database(MsSqlConfiguration.MsSql2012.ConnectionString(connString.ToString())
          .ShowSql()
          .FormatSql())
       .Mappings(
           m => m.AutoMappings.Add(MappingHelper.GetNhibernateServicesMappings(true, true)))
       .ExposeConfiguration(cfg =>
        {
            SchemaMetadataUpdater.QuoteTableAndColumns(cfg);
            BuildSchema(cfg);
        })
        .BuildSessionFactory();

    return sessionFactory;
}

To auto create the tables:

private static void BuildSchema(Configuration cfg)
{
   new SchemaUpdate(cfg).Execute(false, true);
}  

About

Nhibernate persistence layer for IdentityServer v3

Resources

License

Stars

Watchers

Forks

Packages

No packages published