public void RegisterAggregateService_WithType_RegistersServiceInterface()
        {
            var builder = new ContainerBuilder();
            builder.RegisterAggregateService(typeof(IMyContext));
            var container = builder.Build();

            Assert.That(container.IsRegistered<IMyContext>());
        }
        protected override void Load(ContainerBuilder builder)
        {
            // Aggregate Services
            builder.RegisterAggregateService<IComponents>();

            // Settings
            builder.RegisterType<CodeGenerator>().As<ICodeGenerator>();
            builder.RegisterType<EmailSender>().As<IEmailSender>();
            builder.RegisterType<SmsSender>().As<ISmsSender>();
        }
        public void RegisterAggregateService_IsPerDependencyScoped()
        {
            var builder = new ContainerBuilder();
            builder.RegisterAggregateService<IMyContext>();
            builder.RegisterInstance(new Mock<IMyService>().Object);
            var container = builder.Build();

            var firstInstance = container.Resolve<IMyContext>();
            var secondInstance = container.Resolve<IMyContext>();

            Assert.That(firstInstance, Is.Not.SameAs(secondInstance));
        }
        public void Setup()
        {
            _someDependencyMock = new Mock<ISomeDependency>().Object;
            _someOtherDependencyMock = new Mock<ISomeOtherDependency>().Object;

            var builder = new ContainerBuilder();
            builder.RegisterAggregateService<ISubService>();
            builder.RegisterInstance(_someDependencyMock);
            builder.RegisterInstance(_someOtherDependencyMock);
            _container = builder.Build();

            _aggregateService = _container.Resolve<ISubService>();
        }
        public void RegisterAggregateService_DifferentLifeTimeScopes_YieldsDifferentInstances()
        {
            var builder = new ContainerBuilder();
            builder.RegisterAggregateService(typeof(IMyContext));
            builder.RegisterType<MyServiceImpl>()
                .As<IMyService>()
                .InstancePerLifetimeScope();
            var container = builder.Build();

            var rootScope = container.Resolve<IMyContext>();
            var subScope = container.BeginLifetimeScope().Resolve<IMyContext>();

            Assert.That(rootScope.MyService, Is.Not.SameAs(subScope.MyService));
        }
        protected override void Load(ContainerBuilder builder)
        {
            // Aggregate Services
            builder.RegisterAggregateService<IServices>();
            builder.RegisterAggregateService<IAdminServices>();

            // All Services
            builder.RegisterAssemblyTypes(ThisAssembly)
                .Where(t => t.Name.EndsWith("Service"))
                .PropertiesAutowired()
                .AsImplementedInterfaces();

            // Settings
            builder.RegisterType<DictionaryAdapterFactory>().As<IDictionaryAdapterFactory>().SingleInstance();

            // Resolve ISettings by resolving the DictionaryAdapterFactory and initialising it with AppSettings from web.config
            builder.Register(x => x.Resolve<IDictionaryAdapterFactory>()
                .GetAdapter<ISettings>(ConfigurationManager.AppSettings))
                .As<ISettings>().SingleInstance();

            // Resolve the specified settings by resolving ISettings then just taking the appropriate property
            builder.Register(x => x.Resolve<ISettings>().Twilio).As<ITwilioSettings>();
            builder.Register(x => x.Resolve<ISettings>().Aws).As<IAwsSettings>();
        }
Esempio n. 7
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<RiskContext>().As<IRiskContext>().InstancePerRequest();
            builder.RegisterType<RiskContext>().As<DbContext>().InstancePerRequest();

            builder.RegisterAggregateService<IServices>();

            builder.RegisterType<CustomerService>().As<ICustomerService>();
            builder.RegisterType<SettledBetService>().As<ISettledBetService>();
            builder.RegisterType<UnsettledBetService>().As<IUnsettledBetService>();
            builder.RegisterType<CustomerAnalysisService>().As<ICustomerAnalysisService>();
            builder.RegisterType<UnsettledBetAnalysisService>().As<IUnsettledBetAnalysisService>();
            builder.RegisterType<CustomerCalculatorService>().As<ICustomerCalculatorService>();
            builder.RegisterType<BetCalculatorService>().As<IBetCalculatorService>();

            base.Load(builder);
        }
        public void Setup()
        {
            _someDependencyMock = new Mock<ISomeDependency>().Object;

            var builder = new ContainerBuilder();
            builder.RegisterAggregateService<IMyContext>();
            builder.RegisterType<MyServiceImpl>()
                .As<IMyService>()
                .InstancePerDependency();
            builder.RegisterInstance(_someDependencyMock);
            _container = builder.Build();

            _aggregateService = _container.Resolve<IMyContext>();
        }
 public void RegisterAggregateService_WithNullInterfaceType_ThrowsArgumentNullException()
 {
     var builder = new ContainerBuilder();
     builder.RegisterAggregateService(null);
 }
 public void RegisterAggregateService_WithNonInterfaceType_ThrowsArgumentException()
 {
     var builder = new ContainerBuilder();
     builder.RegisterAggregateService(typeof(MyServiceImpl));
 }