コード例 #1
0
        protected BaseUnitTestClass(bool disableIoc)
        {
            UnitTestTools.IsInUnitTestMode        = true;
            UnitTestTools.IsInIntegrationTestMode = GetType().Assembly.GetName().Name.Contains(".Integration.");

            if (!UnitTestTools.IsInIntegrationTestMode && !disableIoc)
            {
                _testFactory = new TestScopeFactory();
                DIManager.Init(_testFactory);
            }
        }
コード例 #2
0
        public void PostBootstrapp_Action_Should_Be_Give_Scope_If_IoC_Configured()
        {
            bool?scopeIsNullb1 = null;
            bool?scopeIsNullb2 = null;

            void lambda1(PostBootstrappingContext c) => scopeIsNullb1 = c.Scope == null;
            void lambda2(PostBootstrappingContext c) => scopeIsNullb2 = c.Scope == null;

            var b  = new Bootstrapper();
            var b2 = new Bootstrapper();

            try
            {
                var s = new Mock <IBootstrapperService>();
                s.Setup(m => m.BootstrappAction).Returns(_ => { });
                s.SetupGet(m => m.ServiceType).Returns(BootstrapperServiceType.Other);
                b.AddService(s.Object);
                b.OnPostBootstrapping += lambda1;

                b.Bootstrapp();

                scopeIsNullb1.Should().HaveValue();
                scopeIsNullb1.Value.Should().BeTrue();

                var s2 = new Mock <IBootstrapperService>();
                s2.Setup(m => m.BootstrappAction).Returns(_ =>
                {
                    DIManager.Init(new TestScopeFactory());
                });
                b2.AddService(s2.Object);
                b2.OnPostBootstrapping += lambda2;

                b2.Bootstrapp();

                scopeIsNullb2.Should().HaveValue();
                scopeIsNullb2.Value.Should().BeFalse();
            }
            finally
            {
                b.OnPostBootstrapping  -= lambda1;
                b2.OnPostBootstrapping -= lambda2;
            }
        }
コード例 #3
0
ファイル: Bootstrapper.ext.cs プロジェクト: sputier/CQELight
        public static Bootstrapper UseMicrosoftDependencyInjection(this Bootstrapper bootstrapper,
                                                                   IServiceCollection services, params string[] excludedDllsForAutoRegistration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var service = new MicrosoftDependencyInjectionService
            {
                BootstrappAction = (ctx) =>
                {
                    AddComponentRegistrationToContainer(services, bootstrapper.IoCRegistrations);
                    AddAutoRegisteredTypes(bootstrapper, services, excludedDllsForAutoRegistration);
                    DIManager.Init(new MicrosoftScopeFactory(services));
                }
            };

            bootstrapper.AddService(service);
            return(bootstrapper);
        }
コード例 #4
0
        public static Bootstrapper UseMicrosoftDependencyInjection(this Bootstrapper bootstrapper,
                                                                   IServiceCollection services, params string[] excludedDllsForAutoRegistration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var service = new MicrosoftDependencyInjectionService
                              (_ =>
            {
                AddComponentRegistrationToContainer(services, bootstrapper.IoCRegistrations.ToList());
                AddAutoRegisteredTypes(bootstrapper, services, excludedDllsForAutoRegistration);
                services.AddScoped <IScopeFactory>(s => new MicrosoftScopeFactory(s));
                services.AddScoped <IScope>(s => s.GetRequiredService <IScopeFactory>().CreateScope());
                DIManager.Init(new MicrosoftScopeFactory(services));
            }
                              );

            bootstrapper.AddService(service);
            return(bootstrapper);
        }
コード例 #5
0
 private static void InitDIManagerAndCreateScopeFactory(ILifetimeScope scope)
 => DIManager.Init(new AutofacScopeFactory(scope));
コード例 #6
0
        private static void InitDIManagerAndCreateScopeFactory(ILifetimeScope scope)
        {
            var factory = new AutofacScopeFactory(scope);

            DIManager.Init(factory);
        }