public ClientRegistry()
 {
     this.AddSingleton <IConfigurationService, ConfigurationService>();
     this.AddSingleton <IApiClient, ApiClient>();
     this.AddSingleton <IEstateClient, EstateClient>();
     this.AddSingleton <IFileProcessorClient, FileProcessorClient>();
     this.AddSingleton <IEstateReportingClient, EstateReportingClient>();
     this.AddSingleton <Func <String, String> >(container => (serviceName) =>
     {
         return(ConfigurationReader.GetBaseServerUri(serviceName).OriginalString);
     });
     this.AddSingleton <HttpClient>();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the user by identifier.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <GetUserResponse> GetUserById(Guid userId,
                                                        CancellationToken cancellationToken)
        {
            GetUserResponse response = null;

            using (HttpClient client = new HttpClient())
            {
                String uri = $"{ConfigurationReader.GetBaseServerUri("SecurityService")}api/user?userId={userId}";

                HttpResponseMessage httpResponse = await client.GetAsync(uri, CancellationToken.None).ConfigureAwait(false);

                Logger.LogInformation($"Status Code: {httpResponse.StatusCode}");

                String responseContent = await this.HandleResponse(httpResponse, cancellationToken);

                response = JsonConvert.DeserializeObject <GetUserResponse>(responseContent);
            }

            return(response);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the role.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <CreateRoleResponse> CreateRole(CreateRoleRequest request,
                                                          CancellationToken cancellationToken)
        {
            CreateRoleResponse response = null;

            String        requestSerialised = JsonConvert.SerializeObject(request);
            StringContent content           = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

            using (HttpClient client = new HttpClient())
            {
                String uri = $"{ConfigurationReader.GetBaseServerUri("SecurityService")}api/role";

                HttpResponseMessage httpResponse = await client.PostAsync(uri, content, CancellationToken.None).ConfigureAwait(false);

                Logger.LogInformation($"Status Code: {httpResponse.StatusCode}");

                String responseContent = await this.HandleResponse(httpResponse, cancellationToken);

                response = JsonConvert.DeserializeObject <CreateRoleResponse>(responseContent);
            }

            return(response);
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigurationReader.Initialise(Startup.Configuration);

            Startup.ConfigureEventStoreSettings();

            this.ConfigureMiddlewareServices(services);

            services.AddTransient <IMediator, Mediator>();

            Boolean useConnectionStringConfig = Boolean.Parse(ConfigurationReader.GetValue("AppSettings", "UseConnectionStringConfig"));

            if (useConnectionStringConfig)
            {
                String connectionStringConfigurationConnString = ConfigurationReader.GetConnectionString("ConnectionStringConfiguration");
                services.AddSingleton <IConnectionStringConfigurationRepository, ConnectionStringConfigurationRepository>();
                services.AddTransient <ConnectionStringConfigurationContext>(c =>
                {
                    return(new ConnectionStringConfigurationContext(connectionStringConfigurationConnString));
                });

                // TODO: Read this from a the database and set
            }
            else
            {
                services.AddEventStoreClient(Startup.ConfigureEventStoreSettings);
                services.AddEventStoreProjectionManagementClient(Startup.ConfigureEventStoreSettings);
                services.AddEventStorePersistentSubscriptionsClient(Startup.ConfigureEventStoreSettings);

                services.AddSingleton <IConnectionStringConfigurationRepository, ConfigurationReaderConnectionStringRepository>();
            }


            services.AddTransient <IEventStoreContext, EventStoreContext>();
            services.AddSingleton <IMessagingDomainService, MessagingDomainService>();
            services.AddSingleton <IAggregateRepository <EmailAggregate, DomainEventRecord.DomainEvent>, AggregateRepository <EmailAggregate, DomainEventRecord.DomainEvent> >();
            services.AddSingleton <IAggregateRepository <SMSAggregate, DomainEventRecord.DomainEvent>, AggregateRepository <SMSAggregate, DomainEventRecord.DomainEvent> >();

            RequestSentToEmailProviderEvent r = new RequestSentToEmailProviderEvent(Guid.Parse("2AA2D43B-5E24-4327-8029-1135B20F35CE"), "", new List <String>(),
                                                                                    "", "", true);

            TypeProvider.LoadDomainEventsTypeDynamically();

            this.RegisterEmailProxy(services);
            this.RegisterSMSProxy(services);

            // request & notification handlers
            services.AddTransient <ServiceFactory>(context =>
            {
                return(t => context.GetService(t));
            });

            services.AddSingleton <IRequestHandler <SendEmailRequest, String>, MessagingRequestHandler>();
            services.AddSingleton <IRequestHandler <SendSMSRequest, String>, MessagingRequestHandler>();

            services.AddSingleton <Func <String, String> >(container => (serviceName) =>
            {
                return(ConfigurationReader.GetBaseServerUri(serviceName).OriginalString);
            });
            var httpMessageHandler = new SocketsHttpHandler
            {
                SslOptions =
                {
                    RemoteCertificateValidationCallback = (sender,
                                                           certificate,
                                                           chain,
                                                           errors) => true,
                }
            };
            HttpClient httpClient = new HttpClient(httpMessageHandler);

            services.AddSingleton(httpClient);

            Dictionary <String, String[]> eventHandlersConfiguration = new Dictionary <String, String[]>();

            if (Startup.Configuration != null)
            {
                IConfigurationSection section = Startup.Configuration.GetSection("AppSettings:EventHandlerConfiguration");

                if (section != null)
                {
                    Startup.Configuration.GetSection("AppSettings:EventHandlerConfiguration").Bind(eventHandlersConfiguration);
                }
            }
            services.AddSingleton <EmailDomainEventHandler>();
            services.AddSingleton <SMSDomainEventHandler>();
            services.AddSingleton <Dictionary <String, String[]> >(eventHandlersConfiguration);

            services.AddSingleton <Func <Type, IDomainEventHandler> >(container => (type) =>
            {
                IDomainEventHandler handler = container.GetService(type) as IDomainEventHandler;
                return(handler);
            });


            services.AddSingleton <IDomainEventHandlerResolver, DomainEventHandlerResolver>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientRegistry"/> class.
        /// </summary>
        public ClientRegistry()
        {
            this.AddSingleton<ISecurityServiceClient, SecurityServiceClient>();
            this.AddSingleton<IEstateClient, EstateClient>();
            this.AddSingleton<ITransactionProcessorClient, TransactionProcessorClient>();

            this.AddSingleton<Func<String, String>>(container => serviceName => { return ConfigurationReader.GetBaseServerUri(serviceName).OriginalString; });

            var httpMessageHandler = new SocketsHttpHandler
                                     {
                                         SslOptions =
                                         {
                                             RemoteCertificateValidationCallback = (sender,
                                                                                    certificate,
                                                                                    chain,
                                                                                    errors) => true,
                                         }
                                     };
            HttpClient httpClient = new HttpClient(httpMessageHandler);
            this.AddSingleton(httpClient);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        /// <summary>
        /// Configures the services.
        /// </summary>
        /// <param name="services">The services.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigurationReader.Initialise(Startup.Configuration);

            Startup.ConfigureEventStoreSettings();

            this.ConfigureMiddlewareServices(services);

            services.AddTransient <IMediator, Mediator>();
            services.AddSingleton <IEstateManagementManager, EstateManagementManager>();

            Boolean useConnectionStringConfig = Boolean.Parse(ConfigurationReader.GetValue("AppSettings", "UseConnectionStringConfig"));

            if (useConnectionStringConfig)
            {
                String connectionStringConfigurationConnString = ConfigurationReader.GetConnectionString("ConnectionStringConfiguration");
                services.AddSingleton <IConnectionStringConfigurationRepository, ConnectionStringConfigurationRepository>();
                services.AddTransient <ConnectionStringConfigurationContext>(c =>
                {
                    return(new ConnectionStringConfigurationContext(connectionStringConfigurationConnString));
                });

                // TODO: Read this from a the database and set
            }
            else
            {
                services.AddEventStoreClient(Startup.ConfigureEventStoreSettings);
                services.AddEventStoreProjectionManagerClient(Startup.ConfigureEventStoreSettings);
                services.AddEventStorePersistentSubscriptionsClient(Startup.ConfigureEventStoreSettings);
                services.AddSingleton <IConnectionStringConfigurationRepository, ConfigurationReaderConnectionStringRepository>();
            }

            services.AddTransient <IEventStoreContext, EventStoreContext>();
            services.AddSingleton <IEstateManagementRepository, EstateManagementRepository>();
            services.AddSingleton <IDbContextFactory <EstateReportingContext>, DbContextFactory <EstateReportingContext> >();

            Dictionary <String, String[]> handlerEventTypesToSilentlyHandle = new Dictionary <String, String[]>();

            if (Startup.Configuration != null)
            {
                IConfigurationSection section = Startup.Configuration.GetSection("AppSettings:HandlerEventTypesToSilentlyHandle");

                if (section != null)
                {
                    Startup.Configuration.GetSection("AppSettings:HandlerEventTypesToSilentlyHandle").Bind(handlerEventTypesToSilentlyHandle);
                }
            }

            services.AddSingleton <Func <String, EstateReportingContext> >(cont => (connectionString) => { return(new EstateReportingContext(connectionString)); });

            DomainEventTypesToSilentlyHandle eventTypesToSilentlyHandle = new DomainEventTypesToSilentlyHandle(handlerEventTypesToSilentlyHandle);

            services.AddTransient <IEventStoreContext, EventStoreContext>();
            services.AddSingleton <IAggregateRepository <EstateAggregate.EstateAggregate, DomainEventRecord.DomainEvent>, AggregateRepository <EstateAggregate.EstateAggregate, DomainEventRecord.DomainEvent> >();
            services.AddSingleton <IAggregateRepository <MerchantAggregate.MerchantAggregate, DomainEventRecord.DomainEvent>, AggregateRepository <MerchantAggregate.MerchantAggregate, DomainEventRecord.DomainEvent> >();
            services.AddSingleton <IAggregateRepository <ContractAggregate.ContractAggregate, DomainEventRecord.DomainEvent>, AggregateRepository <ContractAggregate.ContractAggregate, DomainEventRecord.DomainEvent> >();
            services.AddSingleton <IEstateDomainService, EstateDomainService>();
            services.AddSingleton <IMerchantDomainService, MerchantDomainService>();
            services.AddSingleton <IContractDomainService, ContractDomainService>();
            services.AddSingleton <IModelFactory, ModelFactory>();
            services.AddSingleton <Factories.IModelFactory, Factories.ModelFactory>();
            services.AddSingleton <ISecurityServiceClient, SecurityServiceClient>();

            ContractCreatedEvent c = new ContractCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "");
            MerchantCreatedEvent m = new MerchantCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), "", DateTime.Now);
            EstateCreatedEvent   e = new EstateCreatedEvent(Guid.NewGuid(), "");

            TypeProvider.LoadDomainEventsTypeDynamically();

            // request & notification handlers
            services.AddTransient <ServiceFactory>(context =>
            {
                return(t => context.GetService(t));
            });

            services.AddSingleton <IRequestHandler <CreateEstateRequest, String>, EstateRequestHandler>();
            services.AddSingleton <IRequestHandler <CreateEstateUserRequest, Guid>, EstateRequestHandler>();
            services.AddSingleton <IRequestHandler <AddOperatorToEstateRequest, String>, EstateRequestHandler>();

            services.AddSingleton <IRequestHandler <CreateMerchantRequest, String>, MerchantRequestHandler>();
            services.AddSingleton <IRequestHandler <AssignOperatorToMerchantRequest, String>, MerchantRequestHandler>();
            services.AddSingleton <IRequestHandler <CreateMerchantUserRequest, Guid>, MerchantRequestHandler>();
            services.AddSingleton <IRequestHandler <AddMerchantDeviceRequest, String>, MerchantRequestHandler>();
            services.AddSingleton <IRequestHandler <MakeMerchantDepositRequest, Guid>, MerchantRequestHandler>();

            services.AddSingleton <IRequestHandler <CreateContractRequest, String>, ContractRequestHandler>();
            services.AddSingleton <IRequestHandler <AddProductToContractRequest, String>, ContractRequestHandler>();
            services.AddSingleton <IRequestHandler <AddTransactionFeeForProductToContractRequest, String>, ContractRequestHandler>();

            services.AddSingleton <Func <String, String> >(container => (serviceName) =>
            {
                return(ConfigurationReader.GetBaseServerUri(serviceName).OriginalString);
            });

            HttpClientHandler httpClientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (message,
                                                             certificate2,
                                                             arg3,
                                                             arg4) =>
                {
                    return(true);
                }
            };
            HttpClient httpClient = new HttpClient(httpClientHandler);

            services.AddSingleton <HttpClient>(httpClient);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientRegistry"/> class.
        /// </summary>
        public ClientRegistry()
        {
            this.AddSingleton <ISecurityServiceClient, SecurityServiceClient>();
            this.AddSingleton <IVoucherManagementClient, VoucherManagementClient>();
            this.AddSingleton <Func <String, String> >(container => serviceName => { return(ConfigurationReader.GetBaseServerUri(serviceName).OriginalString); });
            HttpClientHandler httpClientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (message,
                                                             certificate2,
                                                             arg3,
                                                             arg4) =>
                {
                    return(true);
                }
            };
            HttpClient httpClient = new HttpClient(httpClientHandler);

            this.AddSingleton(httpClient);
        }