public void given_transient_registration()
 {
     container = new Container();
     container.Register <IEFCoreInstaller, ExampleInstaller>(Reuse.Singleton, FactoryMethod.ConstructorWithResolvableArguments);
     container.AddAutoTx();
     container.AddEFCore(DefaultLifeStyleOption.Transient);
 }
        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 <IEFCoreInstaller, ExampleInstaller>(Reuse.Singleton, FactoryMethod.ConstructorWithResolvableArguments);
            container.AddAutoTx();
            container.AddEFCore(DefaultLifeStyleOption.PerWebRequest);

            //var app = new HttpApplication();
            //var lifestyle = new PerWebRequestLifestyleModule();
            //lifestyle.Init(app);
        }
예제 #3
0
        public void SetUp()
        {
            _Container = new Container();

            _Container.Register <IHaveLifestyle, PerTxClass>(AutoTxReuse.PerTransaction, Parameters.Of.Type(request => "ordinary"), serviceKey: "ordinary");
            _Container.Register <IHaveLifestyle, PerTxClass>(AutoTxReuse.PerTransaction, Parameters.Of.Type(request => "special"), serviceKey: "special");
            _Container.Register <IHaveLifestyle, TransientClass>(Reuse.Transient, serviceKey: "transient");

            _Container.Register <IHaveLifestyle>(Made.Of(
                                                     () => DefaultToTransientLifeStyleFactory.CreateHavingLifestyle(Arg.Of <IContainer>(), Arg.Of <ITransactionManager>()),
                                                     request => request.Parent.ImplementationType));

            _Container.AddAutoTx();
        }
예제 #4
0
        public void SetUp()
        {
            _Container = new Container();
            _Container.Register <IServiceWithTransaction, SimpleServiceWithTransaction>(Reuse.Scoped);
            _Container.Register <SimpleServiceWithTransaction>(Reuse.Scoped);
            _Container.Register <SimpleServiceWithTransaction2>(Reuse.Scoped);
            _Container.Register <EmptyServiceWithInfo>(Reuse.Scoped);
            _Container.Register <ServiceAccessor>(Reuse.Scoped);

            // The same setup configuration as TransactionInterceptor:
            _Container.Register <ServiceWithParentInfo>(Reuse.Transient, setup: Setup.With(asResolutionCall: true));

            // In-memory logging
            _LoggerProvider = new InMemoryLoggerProvider();
            _LoggerFactory  = new LoggerFactory(new[] { _LoggerProvider });
            _Container.UseInstance <ILoggerFactory>(_LoggerFactory);

            _Container.AddAutoTx();
        }
예제 #5
0
        // 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>());
        }
예제 #6
0
        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));
            }
        }