Exemplo n.º 1
0
        public void RepositoryTest()
        {
            var registered             = LocalIocManager.IsRegistered(typeof(IUserRepository));
            var checkoffAutoRegistered = LocalIocManager.IsRegistered(typeof(ICheckoffAutoAcpRepository));

            if (checkoffAutoRegistered && registered)
            {
                //var userRepository = LocalIocManager.IocContainer.Resolve<IUserRepository>();

                //var user = userRepository.GetAllUsers().FirstOrDefault();
                //if (user != null)
                //    user.ShouldNotBeNull();

                var checkoffAuto = LocalIocManager.IocContainer.Resolve <ICheckoffAutoAcpRepository>();

                var one = checkoffAuto.GetAll().FirstOrDefault();
                one.ShouldNotBeNull();
            }

            var domainServiceRegistered = LocalIocManager.IsRegistered(typeof(IUserDomainService));

            if (domainServiceRegistered)
            {
                var userDomainService = LocalIocManager.IocContainer.Resolve <IUserDomainService>();
            }
        }
Exemplo n.º 2
0
 protected void EnsureClassRegistered(Type type, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Transient)
 {
     if (!LocalIocManager.IsRegistered(type))
     {
         if (!type.IsClass || type.IsAbstract)
         {
             throw new WindException("Can not register " + type.Name + ". It should be a non-abstract class. If not, it should be registered before.");
         }
         LocalIocManager.Register(type, lifeStyle);
     }
 }
Exemplo n.º 3
0
        public void if_not_registered_should_work()
        {
            Building(builder =>
            {
                builder.RegisterServices(r => r.UseBuilder(cb =>
                {
                    cb.RegisterType <ServiceA>().As <IService>();
                    cb.RegisterType <ServiceB>().As <IService>().IfNotRegistered(typeof(ServiceA));
                }));
            });

            LocalIocManager.IsRegistered <ServiceB>().ShouldBe(false);
        }
Exemplo n.º 4
0
        public void RegisterIfAbsent_should_work_with_type_parameters_()
        {
            Building(builder =>
            {
                builder.RegisterServices(r =>
                {
                    r.Register <IService, ServiceA>();
                    r.RegisterIfAbsent(typeof(IService), typeof(ServiceB));
                });
            });

            LocalIocManager.IsRegistered(typeof(ServiceB)).ShouldBe(false);
            The <IService>().ShouldBeAssignableTo <ServiceA>();
        }
Exemplo n.º 5
0
        public void RegisterIfAbsent_should_work_with_generic_T()
        {
            Building(builder =>
            {
                builder.RegisterServices(r =>
                {
                    r.Register <IService, ServiceA>();
                    r.RegisterIfAbsent <IService, ServiceB>();
                });
            });

            LocalIocManager.IsRegistered(typeof(ServiceB)).Should().Be(false);
            The <IService>().Should().BeAssignableTo <ServiceA>();
        }
Exemplo n.º 6
0
        public void RegisterIfAbsent_should_work_with_TGeneric_propertyinjection_should_not_be_null()
        {
            Building(builder =>
            {
                builder.RegisterServices(r =>
                {
                    r.RegisterType(typeof(MyClass));
                    r.RegisterIfAbsent <IService, ServiceB>();
                    r.RegisterIfAbsent <MyClass>();
                });
            });

            LocalIocManager.IsRegistered(typeof(ServiceB)).ShouldBe(true);
            The <IService>().ShouldBeAssignableTo <ServiceB>();
            The <IService>().MyProperty.ShouldNotBeNull();
        }
Exemplo n.º 7
0
        public void FluentBootstrapper_Should_Work()
        {
            IResolver resolver = Building(builder =>
            {
                builder.UseNLog()
                .UseEventStore()
                .UseRabbitMQ()
                .RegisterServices(r => r.RegisterAssemblyByConvention(Assembly.Load(new AssemblyName("Autofac.Extras.IocManager.Tests"))));
            });

            resolver.IsRegistered <IEventStore>().ShouldBe(true);
            resolver.IsRegistered <ILogger>().ShouldBe(true);
            resolver.IsRegistered <IBus>().ShouldBe(true);

            LocalIocManager.IsRegistered <IEventStore>().ShouldBe(true);
            LocalIocManager.IsRegistered <ILogger>().ShouldBe(true);
            LocalIocManager.IsRegistered <IBus>().ShouldBe(true);
        }
Exemplo n.º 8
0
        public void RegisterIfAbsent_should_work_on_propertyInjection()
        {
            Building(builder =>
            {
                builder.RegisterServices(r =>
                {
                    r.RegisterIfAbsent <IService, ServiceA>();
                    r.RegisterIfAbsent(typeof(IService), typeof(ServiceB));
                    r.RegisterType(typeof(MyClass));
                });
            });

            LocalIocManager.IsRegistered(typeof(ServiceB)).ShouldBe(false);
            The <IService>().ShouldBeAssignableTo <ServiceA>();

            var instanceA = The <IService>();

            instanceA.MyProperty.ShouldNotBeNull();
        }
Exemplo n.º 9
0
        protected override void PreInitialize()
        {
            base.PreInitialize();

            var visitConnection = DbConnectionFactory.CreateTransient();

            if (!LocalIocManager.IsRegistered <IBatchDataModuleConfiguration>())
            {
                LocalIocManager.Register <IBatchDataModuleConfiguration, BatchDataModuleConfiguration>();
                Resolve <IBatchDataModuleConfiguration>().Connection = visitConnection;
            }

            AbpBootstrapper.PlugInSources.Add(new PlugInTypeListSource(
                                                  typeof(AbpExModule),
                                                  typeof(AbpExEntityFrameworkModule),
                                                  typeof(BatchCoreModule),
                                                  typeof(BatchDataModule),
                                                  typeof(BatchApplicationModule)
                                                  ));
        }
Exemplo n.º 10
0
 public void Test_LocalIocManager()
 {
     Assert.IsFalse(LocalIocManager.IsRegistered <IAbpStartupConfiguration>());
 }