Example #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .CreateLogger();
            Logger.Here().Information("Logger created");

            Config.ConnectionStrings connectionStrings = new Config.ConnectionStrings();
            Configuration.GetSection(Config.ConnectionStrings.SECTION).Bind(connectionStrings);
#if DEBUG
            Logger.Here().Debug("Redis: " + connectionStrings.Redis);
#endif
            ConnectionMultiplexer muxer      = ConnectionMultiplexer.Connect(connectionStrings.Redis);
            IDatabase             redis      = muxer.GetDatabase();
            ISubscriber           subscriber = muxer.GetSubscriber();

            Logger.Here().Information("Subscribing to " + Constants.PubSub.TOPIC_TRANSACTION_PROCESSED);
            subscriber.Subscribe(Constants.PubSub.TOPIC_TRANSACTION_PROCESSED,
                                 Handlers.TransactionProcessHandler(Logger, redis));

            Config.ErxServices erx = new Config.ErxServices();
            Configuration.GetSection(Config.ErxServices.SECTION).Bind(erx);
#if DEBUG
            Logger.Here().Debug("OrderUrlBase: " + erx.OrderUrlBase);
#endif

            var httpHandler = new HttpClientHandler()
            {
                ServerCertificateCustomValidationCallback =
                    HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
            };
            var channel = GrpcChannel.ForAddress(erx.OrderUrlBase,
                                                 new GrpcChannelOptions {
                HttpHandler = httpHandler
            });

            services.AddGrpc();
            services.AddSingleton <IDatabase>(redis);
            services.AddSingleton <IOrderServiceRpcClient>(new OrderServiceRpcClient(channel));

            Logger.Here().Information("END");
        }
Example #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .CreateLogger();
            Logger.Here().Information("Logger created");

            Config.ConnectionStrings connectionStrings = new Config.ConnectionStrings();
            Configuration.GetSection(Config.ConnectionStrings.SECTION).Bind(connectionStrings);
#if DEBUG
            Logger.Here().Debug("DemoExchangeDb: " + connectionStrings.DemoExchangeDb);
            Logger.Here().Debug("Redis: " + connectionStrings.Redis);
#endif
            ConnectionMultiplexer muxer      = ConnectionMultiplexer.Connect(connectionStrings.Redis);
            ISubscriber           subscriber = muxer.GetSubscriber();

            Config.ErxServices erx = new Config.ErxServices();
            Configuration.GetSection(Config.ErxServices.SECTION).Bind(erx);
#if DEBUG
            Logger.Here().Debug("AccountUrlBase: " + erx.AccountUrlBase);
#endif

            var httpHandler = new HttpClientHandler()
            {
                ServerCertificateCustomValidationCallback =
                    HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
            };
            var channel = GrpcChannel.ForAddress(erx.AccountUrlBase,
                                                 new GrpcChannelOptions {
                HttpHandler = httpHandler
            });

            services.AddGrpc();
            services.AddSingleton <Config.ConnectionStrings>(connectionStrings);
            services.AddSingleton <IDemoExchangeDbContextFactory <OrderContext>, OrderContextFactory>();
            services.AddSingleton <ISubscriber>(subscriber);
            services.AddSingleton <IOrderService, DemoExchange.Services.OrderService>();
            services.AddSingleton <IAccountServiceRpcClient>(new AccountServiceRpcClient(channel));

            Logger.Here().Information("END");
        }
Example #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .CreateLogger();
            Logger.Here().Information("Logger created");

            Config.ErxServices erx = new Config.ErxServices();
            Configuration.GetSection(Config.ErxServices.SECTION).Bind(erx);
#if DEBUG
            Logger.Here().Debug("IdentityUrlBase: " + erx.IdentityUrlBase);
            Logger.Here().Debug("AccountUrlBase: " + erx.AccountUrlBase);
            Logger.Here().Debug("OrderUrlBase: " + erx.OrderUrlBase);
            Logger.Here().Debug("QuoteUrlBase: " + erx.QuoteUrlBase);
#endif

            var httpHandler = new HttpClientHandler {
                ServerCertificateCustomValidationCallback =
                    HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
            };
            var accountChannel = GrpcChannel.ForAddress(erx.AccountUrlBase,
                                                        new GrpcChannelOptions {
                HttpHandler = httpHandler
            });
            var orderChannel = GrpcChannel.ForAddress(erx.OrderUrlBase,
                                                      new GrpcChannelOptions {
                HttpHandler = httpHandler
            });
            var quoteChannel = GrpcChannel.ForAddress(erx.QuoteUrlBase,
                                                      new GrpcChannelOptions {
                HttpHandler = httpHandler
            });

            services.AddGrpc();
            services.AddGrpcHttpApi();

            services.AddAuthentication(Constants.Identity.BEARER)
            .AddJwtBearer(Constants.Identity.BEARER, options => {
                options.Authority = erx.IdentityUrlBase;

                options.TokenValidationParameters = new TokenValidationParameters {
                    ValidateAudience = false
                };
            });
            services.AddAuthorization(options => {
                options.AddPolicy(Constants.Identity.POLICY_SCOPE_NAME, policy => {
                    policy.RequireAuthenticatedUser();
                    policy.RequireClaim(Constants.Identity.CLAIM_NAME, Constants.Identity.API_SCOPE);
                });
            });

            services.AddSingleton <IAccountServiceRpcClient>(new AccountServiceRpcClient(accountChannel));
            services.AddSingleton <IOrderServiceRpcClient>(new OrderServiceRpcClient(orderChannel));
            services.AddSingleton <IQuoteServiceRpcClient>(new QuoteServiceRpcClient(quoteChannel));

            services.AddSwaggerGen(c => {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title          = "ER-X",
                    Version        = "v1",
                    Description    = "API for DemoExchange",
                    TermsOfService = new Uri("https://er-x.io/terms"),
                    Contact        = new OpenApiContact {
                        Name  = "ER-X",
                        Email = string.Empty,
                        Url   = new Uri("https://er-x.io"),
                    },
                    License = new OpenApiLicense {
                        Name = "Use under LICX",
                        Url  = new Uri("https://er-x.io/license"),
                    }
                });

                /* Set the comments path
                 * for the Swagger JSON and UI.
                 * var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                 * var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                 * c.IncludeXmlComments(xmlPath);*/
            });
            services.AddGrpcSwagger();

            Logger.Here().Information("END");
        }