public void given_transient_registration() { container = new Container(); container.Register <INHibernateInstaller, ExampleInstaller>(Reuse.Singleton, FactoryMethod.ConstructorWithResolvableArguments); container.AddAutoTx(); container.AddNHibernate(DefaultSessionLifeStyleOption.SessionTransient); }
public void SetUp() { //container = new Container().WithDependencyInjectionAdapter(); // the same configuration as for ASP.NET Core (test per web-request life style) container = new Container(); // use normal Container because rule .WithFactorySelector(Rules.SelectLastRegisteredFactory()) overrides registration configuration container.Register <INHibernateInstaller, ExampleInstaller>(Reuse.Singleton, FactoryMethod.ConstructorWithResolvableArguments); container.AddAutoTx(); container.AddNHibernate(DefaultSessionLifeStyleOption.SessionPerWebRequest); //var app = new HttpApplication(); //var lifestyle = new PerWebRequestLifestyleModule(); //lifestyle.Init(app); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { var dynamicModuleProvider = services.LoadModules(m_configuration, m_environment, m_loggerFactory); services.RegisterIdentity(m_configuration, m_loggerFactory); services.RegisterLocalization(m_configuration, "Localization"); services.RegisterMvc(m_environment) .LoadDynamicControllers(dynamicModuleProvider); services.RegisterApiVersioning(); services.RegisterSwagger(); services.RegisterAuthorizationCore(); services.RegisterAutomapper(); services.RegisterAndConfigureOptions(m_configuration, m_environment); services.ConfigureReverseProxyHeaders(m_configuration); m_container = new Container() .WithDependencyInjectionAdapter(services, throwIfUnresolved: type => type.Name.EndsWith("Controller") ); try { m_container.RegisterAllComponents(); m_container.AddAutoTx(); m_container.AddNHibernate(); } catch (Exception ex) // Any exception can be thrown including exception from database driver, e.g. SqlException { m_loggerFactory.CreateLogger <Startup>().LogCritical(ex, "Unable to initialize NHibernate using Auto Transactions"); throw; } return(m_container.Resolve <IServiceProvider>()); }
private void Start() { container = new Container(); container.Register <ILoggerFactory, NLogLoggerFactory>(Reuse.Singleton, FactoryMethod.ConstructorWithResolvableArguments); container.AddLoggerResolving(); container.Register <INHibernateInstaller, NHibInstaller>(Reuse.Singleton); container.Register <Logger>(Reuse.Singleton); container.AddAutoTx(); container.AddNHibernate(); using (var scope = new ResolveScope <Logger>(container)) { using (var up = new ResolveScope <Configuration>(container)) new SchemaUpdate(up.Service).Execute(false, true); Console.WriteLine("Current log contents:"); Console.WriteLine("[utc date] - [text]"); Console.WriteLine("-------------------"); scope.Service.ReadLog(Console.WriteLine); scope.Service.WriteToLog(string.Format("{0} - Started", DateTime.UtcNow)); } }