0
NHibernate SessionFactoryをシングルトンとSessionとしてスコープで作成しようとすると、.NET Core依存性注入によって処理されます。私は、次のようなStartup.csのものを設定して:NHibernate SessionFactoryが.NETコアで処理DI
services.AddSingleton<NHibernate.ISessionFactory>(factory =>
{
return Fluently
.Configure()
.Database(() =>
{
return FluentNHibernate.Cfg.Db.MsSqlConfiguration
.MsSql2012
.ShowSql()
.ConnectionString(ConnectionString);
})
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Model>())
.BuildSessionFactory();
});
services.AddScoped<NHibernate.ISession>(factory =>
factory
.GetServices<NHibernate.ISessionFactory>()
.First()
.OpenSession()
);
私の質問は - どのように私は正確にリポジトリクラスでは、例えば、セッションまたはSessionFactoryのインスタンスを渡すのですか?