Пример #1
0
        private static ContainerBuilder BuildContainer()
        {
            Console.WriteLine($"BuildContainer:1");
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterModule <PreValidationServiceModule>();

            Console.WriteLine($"BuildContainer:2");
            // get ServiceBus, Azurestorage config values and register container
            var configHelper      = new ConfigurationHelper();
            var serviceBusOptions =
                configHelper.GetSectionValues <ServiceBusOptions>("ServiceBusSettings");

            containerBuilder.RegisterInstance(serviceBusOptions).As <ServiceBusOptions>().SingleInstance();

            Console.WriteLine($"BuildContainer:3");
            var azureStorageOptions =
                configHelper.GetSectionValues <AzureStorageModel>("AzureStorageSection");

            containerBuilder.RegisterInstance(azureStorageOptions).As <AzureStorageModel>().SingleInstance();
            containerBuilder.RegisterInstance(azureStorageOptions).As <IAzureStorageKeyValuePersistenceServiceConfig>().SingleInstance();

            Console.WriteLine($"BuildContainer:4");
            // register logger
            var loggerOptions =
                configHelper.GetSectionValues <LoggerOptions>("LoggerSection");

            containerBuilder.RegisterInstance(loggerOptions).As <LoggerOptions>().SingleInstance();
            containerBuilder.RegisterModule <LoggerModule>();

            Console.WriteLine($"BuildContainer:5");
            var azureRedisCacheOptions = configHelper.GetSectionValues <AzureRedisCacheOptions>("AzureRedisSection");

            containerBuilder.Register(c => new RedisKeyValuePersistenceServiceConfig()
            {
                ConnectionString = azureRedisCacheOptions.RedisCacheConnectionString,
                KeyExpiry        = new TimeSpan(14, 0, 0, 0)
            }).As <IRedisKeyValuePersistenceServiceConfig>().SingleInstance();
            containerBuilder.RegisterType <RedisKeyValuePersistenceService>()
            .Keyed <IKeyValuePersistenceService>(PersistenceStorageKeys.Redis)
            .As <IKeyValuePersistenceService>()
            .InstancePerLifetimeScope();
            containerBuilder.RegisterType <AzureStorageKeyValuePersistenceService>()
            .Keyed <IKeyValuePersistenceService>(PersistenceStorageKeys.AzureStorage)
            .As <IKeyValuePersistenceService>()
            .As <IStreamableKeyValuePersistenceService>()
            .InstancePerLifetimeScope();

            Console.WriteLine($"BuildContainer:6");
            // service bus queue configuration
            var topicConfiguration = new ServiceBusTopicConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.TopicName,
                serviceBusOptions.SubscriptionName);

            Console.WriteLine($"BuildContainer:8");
            var auditPublishConfig = new ServiceBusQueueConfig(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.AuditQueueName,
                Environment.ProcessorCount);

            Console.WriteLine($"BuildContainer:9");
            // register queue services
            containerBuilder.Register(c =>
            {
                var topicSubscriptionSevice =
                    new TopicSubscriptionSevice <JobContextDto>(
                        topicConfiguration,
                        c.Resolve <IJsonSerializationService>(),
                        c.Resolve <ILogger>());
                return(topicSubscriptionSevice);
            }).As <ITopicSubscriptionService <JobContextDto> >();

            Console.WriteLine($"BuildContainer:10");
            containerBuilder.Register(c =>
            {
                var topicPublishService =
                    new TopicPublishService <JobContextDto>(
                        topicConfiguration,
                        c.Resolve <IJsonSerializationService>());
                return(topicPublishService);
            }).As <ITopicPublishService <JobContextDto> >();

            Console.WriteLine($"BuildContainer:11");
            containerBuilder.Register(c => new QueuePublishService <AuditingDto>(
                                          auditPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <AuditingDto> >();

            Console.WriteLine($"BuildContainer:12");
            // Job Status Update Service
            var jobStatusPublishConfig = new JobStatusQueueConfig(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.JobStatusQueueName,
                Environment.ProcessorCount);

            Console.WriteLine($"BuildContainer:13");
            containerBuilder.Register(c => new QueuePublishService <JobStatusDto>(
                                          jobStatusPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <JobStatusDto> >();
            containerBuilder.RegisterType <JobStatus.JobStatus>().As <IJobStatus>();

            Console.WriteLine($"BuildContainer:14");
            // register job context manager
            containerBuilder.RegisterType <Auditor>().As <IAuditor>();
            containerBuilder.RegisterType <JobContextMessageMapper>()
            .As <IMapper <JobContextMessage, JobContextMessage> >();

            Console.WriteLine($"BuildContainer:15");
            // register Job Status
            containerBuilder.Register(c => new JobStatus.JobStatus(
                                          c.Resolve <IQueuePublishService <JobStatusDto> >()))
            .As <IJobStatus>();

            Console.WriteLine($"BuildContainer:16");
            containerBuilder.RegisterType <MessageHandler>().As <IMessageHandler>();

            Console.WriteLine($"BuildContainer:17");
            // register the  callback handle when a new message is received from ServiceBus
            containerBuilder.Register <Func <JobContextMessage, CancellationToken, Task <bool> > >(c => c.Resolve <IMessageHandler>().Handle);

            containerBuilder.RegisterType <JobContextManagerForTopics <JobContextMessage> >().As <IJobContextManager <JobContextMessage> >()
            .InstancePerLifetimeScope();

            Console.WriteLine($"BuildContainer:19");
            containerBuilder.RegisterType <JobContextMessage>().As <IJobContextMessage>()
            .InstancePerLifetimeScope();

            Console.WriteLine($"BuildContainer:20");

            return(containerBuilder);
        }
        public static ContainerBuilder BuildContainer(IConfigurationHelper configHelper)
        {
            var containerBuilder = new ContainerBuilder();

            var topicAndTaskOptions = configHelper.GetSectionValues <TopicAndTaskSectionOptions>("TopicAndTaskSection");

            containerBuilder.RegisterInstance(topicAndTaskOptions).As <ITopicAndTaskSectionOptions>().SingleInstance();

            var larsConfiguration = configHelper.GetSectionValues <LarsConfiguration>("LarsSection");

            containerBuilder.RegisterInstance(larsConfiguration).As <LarsConfiguration>().SingleInstance();

            var dasCommitmentsConfiguration = configHelper.GetSectionValues <DasCommitmentsConfiguration>("DasCommitmentsSection");

            containerBuilder.RegisterInstance(dasCommitmentsConfiguration).As <DasCommitmentsConfiguration>().SingleInstance();

            var orgConfiguration = configHelper.GetSectionValues <OrgConfiguration>("OrgSection");

            containerBuilder.RegisterInstance(orgConfiguration).As <OrgConfiguration>().SingleInstance();

            var easConfiguration = configHelper.GetSectionValues <EasConfiguration>("EasSection");

            containerBuilder.RegisterInstance(easConfiguration).As <EasConfiguration>().SingleInstance();

            var ilrValidationErrorsConfiguration = configHelper.GetSectionValues <IlrValidationErrorsConfiguration>("IlrValidationErrorsSection");

            containerBuilder.RegisterInstance(ilrValidationErrorsConfiguration).As <IlrValidationErrorsConfiguration>().SingleInstance();

            var dataStoreConfiguration = configHelper.GetSectionValues <DataStoreConfiguration>("DataStoreSection");

            containerBuilder.RegisterInstance(dataStoreConfiguration).As <DataStoreConfiguration>().SingleInstance();

            var largeEmployeeConfiguration = configHelper.GetSectionValues <LargeEmployerConfiguration>("LargeEmployerSection");

            containerBuilder.RegisterInstance(largeEmployeeConfiguration).As <LargeEmployerConfiguration>().SingleInstance();

            var dasPaymentsConfiguration = configHelper.GetSectionValues <DASPaymentsConfiguration>("DASPaymentsSection");

            containerBuilder.RegisterInstance(dasPaymentsConfiguration).As <DASPaymentsConfiguration>().SingleInstance();

            var postcodeConfiguration = configHelper.GetSectionValues <PostcodeConfiguration>("PostcodeSection");

            containerBuilder.RegisterInstance(postcodeConfiguration).As <PostcodeConfiguration>().SingleInstance();

            var collectionsManagementConfiguration =
                configHelper.GetSectionValues <CollectionsManagementConfiguration>("CollectionsManagementSection");

            containerBuilder.RegisterInstance(collectionsManagementConfiguration)
            .As <CollectionsManagementConfiguration>().SingleInstance();

            // register azure blob storage service
            var azureBlobStorageOptions = configHelper.GetSectionValues <AzureStorageOptions>("AzureStorageSection");

            containerBuilder.RegisterInstance(azureBlobStorageOptions).As <IAzureStorageOptions>();
            containerBuilder.Register(c =>
                                      new AzureStorageKeyValuePersistenceConfig(
                                          azureBlobStorageOptions.AzureBlobConnectionString,
                                          azureBlobStorageOptions.AzureBlobContainerName))
            .As <IAzureStorageKeyValuePersistenceServiceConfig>().SingleInstance();

            containerBuilder.RegisterType <AzureStorageKeyValuePersistenceService>()
            .As <IKeyValuePersistenceService>()
            .As <IStreamableKeyValuePersistenceService>()
            .InstancePerLifetimeScope();

            // register serialization
            containerBuilder.RegisterType <JsonSerializationService>()
            .As <IJsonSerializationService>();
            containerBuilder.RegisterType <XmlSerializationService>()
            .As <IXmlSerializationService>();

            // get ServiceBus, Azurestorage config values and register container
            var serviceBusOptions =
                configHelper.GetSectionValues <ServiceBusOptions>("ServiceBusSettings");

            containerBuilder.RegisterInstance(serviceBusOptions).As <ServiceBusOptions>().SingleInstance();

            // Version info
            var versionInfo = configHelper.GetSectionValues <VersionInfo>("VersionSection");

            containerBuilder.RegisterInstance(versionInfo).As <IVersionInfo>().SingleInstance();

            // register logger
            var loggerOptions =
                configHelper.GetSectionValues <LoggerOptions>("LoggerSection");

            containerBuilder.RegisterInstance(loggerOptions).As <LoggerOptions>().SingleInstance();
            containerBuilder.RegisterModule <LoggerModule>();

            // auditing
            var auditPublishConfig = new ServiceBusQueueConfig(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.AuditQueueName,
                Environment.ProcessorCount);

            containerBuilder.Register(c => new QueuePublishService <AuditingDto>(
                                          auditPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <AuditingDto> >();

            // get job status queue config values and register container
            var jobStatusQueueOptions =
                configHelper.GetSectionValues <JobStatusQueueOptions>("JobStatusSection");

            containerBuilder.RegisterInstance(jobStatusQueueOptions).As <JobStatusQueueOptions>().SingleInstance();

            // Job Status Update Service
            var jobStatusPublishConfig = new JobStatusQueueConfig(
                jobStatusQueueOptions.JobStatusConnectionString,
                jobStatusQueueOptions.JobStatusQueueName,
                Environment.ProcessorCount);

            containerBuilder.Register(c => new QueuePublishService <JobStatusDto>(
                                          jobStatusPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <JobStatusDto> >();

            // register Job Context services
            var topicConfig = new ServiceBusTopicConfig(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.TopicName,
                serviceBusOptions.ReportingSubscriptionName,
                Environment.ProcessorCount);

            containerBuilder.Register(c =>
            {
                var topicSubscriptionService =
                    new TopicSubscriptionSevice <JobContextDto>(
                        topicConfig,
                        c.Resolve <IJsonSerializationService>(),
                        c.Resolve <ILogger>());
                return(topicSubscriptionService);
            }).As <ITopicSubscriptionService <JobContextDto> >();

            containerBuilder.Register(c =>
            {
                var topicPublishService =
                    new TopicPublishService <JobContextDto>(
                        topicConfig,
                        c.Resolve <IJsonSerializationService>());
                return(topicPublishService);
            }).As <ITopicPublishService <JobContextDto> >();

            // register message mapper
            containerBuilder.RegisterType <DefaultJobContextMessageMapper <JobContextMessage> >().As <IMapper <JobContextMessage, JobContextMessage> >();

            // register MessageHandler
            containerBuilder.RegisterType <MessageHandler>().As <IMessageHandler <JobContextMessage> >().InstancePerLifetimeScope();

            containerBuilder.RegisterType <EntryPoint>().WithAttributeFiltering().InstancePerLifetimeScope();

            containerBuilder.RegisterType <JobContextManager <JobContextMessage> >().As <IJobContextManager <JobContextMessage> >()
            .InstancePerLifetimeScope();

            containerBuilder.RegisterType <JobContextMessage>().As <IJobContextMessage>()
            .InstancePerLifetimeScope();

            containerBuilder.Register(context =>
            {
                CollectionsManagementConfiguration settings = context.Resolve <CollectionsManagementConfiguration>();
                DbContextOptionsBuilder optionsBuilder      = new DbContextOptionsBuilder();
                optionsBuilder.UseSqlServer(
                    settings.CollectionsManagementConnectionString,
                    options => options.EnableRetryOnFailure(3, TimeSpan.FromSeconds(3), new List <int>()));
                return(optionsBuilder.Options);
            })
            .As <DbContextOptions>()
            .InstancePerLifetimeScope();

            containerBuilder.RegisterType <ILR1819_DataStoreEntitiesValid>().As <IIlr1819ValidContext>();
            containerBuilder.Register(context =>
            {
                var optionsBuilder = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>();
                optionsBuilder.UseSqlServer(
                    dataStoreConfiguration.ILRDataStoreValidConnectionString,
                    options => options.EnableRetryOnFailure(3, TimeSpan.FromSeconds(3), new List <int>()));

                return(optionsBuilder.Options);
            })
            .As <DbContextOptions <ILR1819_DataStoreEntitiesValid> >()
            .SingleInstance();

            containerBuilder.RegisterType <ILR1819_DataStoreEntities>().As <IIlr1819RulebaseContext>();
            containerBuilder.Register(context =>
            {
                var optionsBuilder = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>();
                optionsBuilder.UseSqlServer(
                    dataStoreConfiguration.ILRDataStoreConnectionString,
                    options => options.EnableRetryOnFailure(3, TimeSpan.FromSeconds(3), new List <int>()));

                return(optionsBuilder.Options);
            })
            .As <DbContextOptions <ILR1819_DataStoreEntities> >()
            .SingleInstance();

            containerBuilder.RegisterType <DASPaymentsContext>().As <IDASPaymentsContext>();
            containerBuilder.Register(context =>
            {
                var optionsBuilder = new DbContextOptionsBuilder <DASPaymentsContext>();
                optionsBuilder.UseSqlServer(
                    dasPaymentsConfiguration.DASPaymentsConnectionString,
                    options => options.EnableRetryOnFailure(3, TimeSpan.FromSeconds(3), new List <int>()));

                return(optionsBuilder.Options);
            })
            .As <DbContextOptions <DASPaymentsContext> >()
            .SingleInstance();

            containerBuilder.RegisterType <DateTimeProvider.DateTimeProvider>().As <IDateTimeProvider>().InstancePerLifetimeScope();

            RegisterReports(containerBuilder);
            RegisterServices(containerBuilder);
            RegisterBuilders(containerBuilder);
            RegisterRules(containerBuilder);
            RegisterCommands(containerBuilder);

            return(containerBuilder);
        }
Пример #3
0
        public static ContainerBuilder BuildContainer(IConfigurationHelper configHelper)
        {
            var containerBuilder = new ContainerBuilder();

            // register azure blob storage service
            var azureBlobStorageOptions = configHelper.GetSectionValues <AzureStorageOptions>("AzureStorageSection");

            containerBuilder.Register(c =>
                                      new AzureStorageKeyValuePersistenceConfig(
                                          azureBlobStorageOptions.AzureBlobConnectionString,
                                          azureBlobStorageOptions.AzureBlobContainerName))
            .As <IAzureStorageKeyValuePersistenceServiceConfig>().SingleInstance();

            containerBuilder.Register(c =>
                                      new AzureStorageFileServiceConfiguration()
            {
                ConnectionString = azureBlobStorageOptions.AzureBlobConnectionString
            })
            .As <IAzureStorageFileServiceConfiguration>().SingleInstance();

            containerBuilder.RegisterType <AzureStorageFileService>().As <IFileService>().InstancePerLifetimeScope();

            containerBuilder.RegisterType <AzureStorageKeyValuePersistenceService>()
            .As <IKeyValuePersistenceService>()
            .InstancePerLifetimeScope();

            // register serialization
            containerBuilder.RegisterType <JsonSerializationService>()
            .As <IJsonSerializationService>();
            containerBuilder.RegisterType <XmlSerializationService>()
            .As <IXmlSerializationService>();

            // get ServiceBus, Azurestorage config values and register container
            var serviceBusOptions =
                configHelper.GetSectionValues <ServiceBusOptions>("ServiceBusSettings");

            containerBuilder.RegisterInstance(serviceBusOptions).As <ServiceBusOptions>().SingleInstance();

            // persis data options
            var persistDataConfig =
                configHelper.GetSectionValues <PersistDataConfiguration>("DataStoreSection");

            containerBuilder.RegisterInstance(persistDataConfig).As <PersistDataConfiguration>().SingleInstance();

            // Version info
            var versionInfo = configHelper.GetSectionValues <DataStore.Dto.VersionInfo>("VersionSection");

            containerBuilder.RegisterInstance(versionInfo).As <DataStore.Dto.VersionInfo>().SingleInstance();

            // register logger
            var loggerOptions =
                configHelper.GetSectionValues <LoggerOptions>("LoggerSection");

            containerBuilder.RegisterInstance(loggerOptions).As <LoggerOptions>().SingleInstance();
            containerBuilder.RegisterModule <LoggerModule>();

            // auditing
            var auditPublishConfig = new ServiceBusQueueConfig(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.AuditQueueName,
                Environment.ProcessorCount);

            containerBuilder.Register(c => new QueuePublishService <AuditingDto>(
                                          auditPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <AuditingDto> >();

            // get job status queue config values and register container
            var jobStatusQueueOptions =
                configHelper.GetSectionValues <JobStatusQueueOptions>("JobStatusSection");

            containerBuilder.RegisterInstance(jobStatusQueueOptions).As <JobStatusQueueOptions>().SingleInstance();

            // Job Status Update Service
            var jobStatusPublishConfig = new JobStatusQueueConfig(
                jobStatusQueueOptions.JobStatusConnectionString,
                jobStatusQueueOptions.JobStatusQueueName,
                Environment.ProcessorCount);

            containerBuilder.Register(c => new QueuePublishService <JobStatusDto>(
                                          jobStatusPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <JobStatusDto> >();

            // register Jobcontext services
            var topicConfig = new TopicConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.TopicName,
                serviceBusOptions.DataStoreSubscriptionName,
                1,
                maximumCallbackTimeSpan: TimeSpan.FromMinutes(30));

            containerBuilder.Register(c =>
            {
                var topicSubscriptionSevice =
                    new TopicSubscriptionSevice <JobContextDto>(
                        topicConfig,
                        c.Resolve <IJsonSerializationService>(),
                        c.Resolve <ILogger>());
                return(topicSubscriptionSevice);
            }).As <ITopicSubscriptionService <JobContextDto> >();

            containerBuilder.Register(c =>
            {
                var topicPublishSevice =
                    new TopicPublishService <JobContextDto>(
                        topicConfig,
                        c.Resolve <IJsonSerializationService>());
                return(topicPublishSevice);
            }).As <ITopicPublishService <JobContextDto> >();

            containerBuilder.RegisterType <DateTimeProvider.DateTimeProvider>().As <IDateTimeProvider>().SingleInstance();

            // register message mapper
            containerBuilder.RegisterType <DefaultJobContextMessageMapper <JobContextMessage> >().As <IMapper <JobContextMessage, JobContextMessage> >();

            // register MessageHandler
            containerBuilder.RegisterType <MessageHandler>().As <IMessageHandler <JobContextMessage> >().InstancePerLifetimeScope();

            // register Entrypoint
            containerBuilder.RegisterType <EntryPoint>().As <IEntryPoint>()
            .WithAttributeFiltering()
            .InstancePerLifetimeScope();

            // register ValidationError service
            containerBuilder.Register(b => new ValidationErrors(persistDataConfig.IlrValidationErrorsConnectionString))
            .As <IValidationErrors>().InstancePerDependency();

            containerBuilder.RegisterType <JobContextManager <JobContextMessage> >().As <IJobContextManager <JobContextMessage> >()
            .InstancePerLifetimeScope();

            containerBuilder.RegisterType <JobContextMessage>().As <IJobContextMessage>()
            .InstancePerLifetimeScope();

            RegisterMappers(containerBuilder);
            RegisterProviders(containerBuilder);
            RegisterPersistence(containerBuilder);

            return(containerBuilder);
        }