コード例 #1
0
        private static void Initialize()
        {
            lock (InitLock)
            {
                if (!_initialized)
                {
                    var provider = new CompositeMetamodelProvider()
                                   .AddProvider
                                   (
                        new AnnotationsBasedMetamodelProvider()
                                   )
                                   .AddProvider
                                   (
                        new ConventionBasedMetamodelProvider()
                        .AddTypeSerializerRule
                        (
                            t => t == typeof(BigInteger),
                            s => new BigIntegerSerializer()
                        )
                                   );

                    EntityMetamodel.Configure(provider);

                    _initialized = true;
                }
            }
        }
コード例 #2
0
 /// <summary>
 ///    This method is called from assembly's module constructor.
 /// </summary>
 public static void Initialize()
 {
     EntityMetamodel.Configure
     (
         provider: CreateMetamodelProvider()
     );
 }
コード例 #3
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver =
                        new Newtonsoft.Json.Serialization.DefaultContractResolver();
                });

                services.AddSwaggerGen(options =>
                {
                    options.DefaultLykkeConfiguration("v1", "PayInternal API");
                    options.OperationFilter <FileUploadOperationFilter>();
                });

                EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

                var builder     = new ContainerBuilder();
                var appSettings = Configuration.LoadSettings <AppSettings>();

                Log = CreateLogWithSlack(services, appSettings);

                builder.RegisterModule(new AzureRepositories.AutofacModule(
                                           appSettings.Nested(o => o.PayInternalService.Db.MerchantOrderConnString),
                                           appSettings.Nested(o => o.PayInternalService.Db.MerchantConnString),
                                           appSettings.Nested(o => o.PayInternalService.Db.PaymentRequestConnString),
                                           appSettings.Nested(o => o.PayInternalService.Db.TransferConnString),
                                           Log));

                builder.RegisterModule(new Services.AutofacModule(
                                           appSettings.CurrentValue.PayInternalService.ExpirationPeriods,
                                           appSettings.CurrentValue.PayInternalService.TransactionConfirmationCount,
                                           appSettings.CurrentValue.PayInternalService.Blockchain.WalletAllocationPolicy.Policies));

                builder.RegisterModule(new ServiceModule(appSettings, Log));

                builder.Populate(services);

                ApplicationContainer = builder.Build();

                Mapper.Initialize(cfg =>
                {
                    cfg.ConstructServicesUsing(ApplicationContainer.Resolve);
                    cfg.AddProfiles(typeof(AutoMapperProfile));
                    cfg.AddProfiles(typeof(AzureRepositories.AutoMapperProfile));
                    cfg.AddProfiles(typeof(Services.AutoMapperProfile));
                });

                Mapper.AssertConfigurationIsValid();

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                Log?.WriteFatalErrorAsync(nameof(Startup), nameof(ConfigureServices), "", ex).GetAwaiter().GetResult();
                throw;
            }
        }
コード例 #4
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver =
                        new Newtonsoft.Json.Serialization.DefaultContractResolver();
                });

                services.AddSwaggerGen(options =>
                {
                    options.DefaultLykkeConfiguration("v1", "StellarApi API");
                });

                EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

                var builder     = new ContainerBuilder();
                var appSettings = Configuration.LoadSettings <AppSettings>();

                Log = CreateLogWithSlack(services, appSettings);

                builder.RegisterModule(new ServiceModule(appSettings.Nested(x => x.StellarApiService), Log));
                builder.Populate(services);
                ApplicationContainer = builder.Build();

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                Log?.WriteFatalErrorAsync(nameof(Startup), nameof(ConfigureServices), "", ex).GetAwaiter().GetResult();
                throw;
            }
        }
コード例 #5
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver =
                        new Newtonsoft.Json.Serialization.DefaultContractResolver();
                });

                services.AddSwaggerGen(options =>
                {
                    options.DefaultLykkeConfiguration("v1", "LegalEntities API");
                });

                EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

                Mapper.Initialize(cfg =>
                {
                    cfg.AddProfiles(typeof(AzureRepositories.AutoMapperProfile));
                    cfg.AddProfiles(typeof(AutoMapperProfile));
                });

                Mapper.AssertConfigurationIsValid();

                var builder     = new ContainerBuilder();
                var appSettings = Configuration.LoadSettings <AppSettings>();

                Log = CreateLogWithSlack(services, appSettings);

                builder.RegisterModule(new Services.AutofacModule());
                builder.RegisterModule(new AzureRepositories.AutofacModule(
                                           appSettings.Nested(o => o.LegalEntitiesService.Db.DataConnectionString), Log));
                builder.RegisterModule(new AutofacModule(
                                           appSettings.CurrentValue.PersonalDataServiceClient,
                                           appSettings.CurrentValue.AssetsServiceClient,
                                           appSettings.CurrentValue.LegalEntitiesService.AssetsCacheExpirationPeriod,
                                           services,
                                           Log));
                builder.Populate(services);
                ApplicationContainer = builder.Build();

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                Log?.WriteFatalErrorAsync(nameof(Startup), nameof(ConfigureServices), "", ex).GetAwaiter().GetResult();
                throw;
            }
        }
コード例 #6
0
        public void Configure(IApplicationBuilder app, IHostEnvironment env, IApplicationLifetime appLifetime)
        {
            try
            {
                ApplicationContainer = app.ApplicationServices.GetAutofacRoot();

                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseHsts();
                }

                app.UseCorrelation();
#if DEBUG
                app.UseLykkeMiddleware(ServiceName, ex => ex.ToString());
#else
                app.UseLykkeMiddleware(ServiceName, ex => new ErrorResponse {
                    ErrorMessage = ex.Message
                });
#endif

                app.UseRouting();
                app.UseAuthentication();
                app.UseAuthorization();
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();
                });
                app.UseSwagger();
                app.UseSwaggerUI(a => a.SwaggerEndpoint("/swagger/v1/swagger.json", "Main Swagger"));

                appLifetime.ApplicationStarted.Register(() => StartApplication().Wait());
                appLifetime.ApplicationStopping.Register(() => StopApplication().Wait());
                appLifetime.ApplicationStopped.Register(() => CleanUp().Wait());

                var provider = new AnnotationsBasedMetamodelProvider();

                EntityMetamodel.Configure(provider);
            }
            catch (Exception ex)
            {
                Log?.WriteFatalErrorAsync(nameof(Startup), nameof(ConfigureServices), "", ex).Wait();
                throw;
            }
        }
コード例 #7
0
        static IServiceCollection AddBlockchainCommonRepositories(this IServiceCollection services,
                                                                  IReloadingManager <string> connectionStringManager)
        {
            services = services ??
                       throw new ArgumentNullException(nameof(services));

            connectionStringManager = connectionStringManager ??
                                      throw new ArgumentNullException(nameof(connectionStringManager));

            EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

            services.AddSingleton(sp => new AssetRepository(connectionStringManager, sp.GetRequiredService <ILogFactory>()));
            services.AddSingleton(sp => new DepositWalletRepository(connectionStringManager, sp.GetRequiredService <ILogFactory>()));
            services.AddSingleton(sp => new OperationRepository(connectionStringManager, sp.GetRequiredService <ILogFactory>()));

            return(services);
        }
コード例 #8
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                    options.SerializerSettings.Converters.Add(new StringEnumConverter
                    {
                        CamelCaseText = true
                    });
                });

                services.AddSwaggerGen(options =>
                {
                    options.DefaultLykkeConfiguration("v1", "Zcash.Api API");
                    options.DescribeAllEnumsAsStrings();
                    options.DescribeStringEnumsInCamelCase();
                });

                EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

                var builder     = new ContainerBuilder();
                var appSettings = Configuration.LoadSettings <AppSettings>();

                Log = CreateLogWithSlack(services, appSettings);

                builder.RegisterModule(new ServiceModule(appSettings.Nested(x => x.ZcashApi), Log));
                builder.Populate(services);
                ApplicationContainer = builder.Build();

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                Log?.WriteFatalErrorAsync(nameof(Startup), nameof(ConfigureServices), "", ex).GetAwaiter().GetResult();
                throw;
            }
        }
コード例 #9
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            return(services.BuildServiceProvider <AppSettings>(options =>
            {
                EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

                options.SwaggerOptions = _swaggerOptions;

                options.Logs = logs =>
                {
                    logs.AzureTableName = "BitcoinApiLog";
                    logs.AzureTableConnectionStringResolver = settings => settings.Bitcoin.Db.LogsConnString;

                    logs.Extended = extendedLogs =>
                    {
                        extendedLogs.AddAdditionalSlackChannel("BlockChainIntegration");
                        extendedLogs.AddAdditionalSlackChannel("BlockChainIntegrationImportantMessages",
                                                               channelOptions => { channelOptions.MinLogLevel = LogLevel.Warning; });
                    };
                };
            }));
        }
コード例 #10
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

            Mapper.Initialize(cfg =>
            {
                cfg.AddProfiles(typeof(AzureRepositories.AutoMapperProfile));
                cfg.AddProfiles(typeof(AutoMapperProfile));
            });

            Mapper.AssertConfigurationIsValid();

            return(services.BuildServiceProvider <AppSettings>(options =>
            {
                options.SwaggerOptions = _swaggerOptions;

                options.Logs = logs =>
                {
                    logs.AzureTableName = "AssetDisclaimersLog";
                    logs.AzureTableConnectionStringResolver = settings => settings.AssetDisclaimersService.Db.LogsConnectionString;
                };
            }));
        }
コード例 #11
0
        public RepositoryFactory(
            ILog log,
            IReloadingManager <DbSettings> settings)
        {
            _log = log;
            _connectionString = settings.ConnectionString(x => x.DataConnectionString);

            var provider = new CompositeMetamodelProvider()
                           .AddProvider
                           (
                new AnnotationsBasedMetamodelProvider()
                           )
                           .AddProvider
                           (
                new ConventionBasedMetamodelProvider()
                .AddTypeSerializerRule
                (
                    t => t == typeof(BigInteger),
                    s => new BigIntegerSerializer()
                )
                           );

            EntityMetamodel.Configure(provider);
        }
コード例 #12
0
        public static void RegisterDbModule(
            this ContainerBuilder builder,
            string connectionString,
            string userConnectionString,
            string secretsConnString)
        {
            var provider = new AnnotationsBasedMetamodelProvider();

            EntityMetamodel.Configure(provider);

            var conString        = ConstantReloadingManager.From(connectionString);
            var userConString    = ConstantReloadingManager.From(userConnectionString);
            var secretsConString = ConstantReloadingManager.From(secretsConnString);

            builder.Register(c =>
                             new ServiceTokenRepository(
                                 AzureTableStorage <ServiceTokenEntity> .Create(conString, "ServiceToken", c.Resolve <ILogFactory>())))
            .As <IServiceTokenRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new UserRepository(
                                 AzureTableStorage <UserEntity> .Create(userConString, "User", c.Resolve <ILogFactory>())))
            .As <IUserRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new RoleRepository(
                                 AzureTableStorage <RoleEntity> .Create(userConString, "Role", c.Resolve <ILogFactory>())))
            .As <IRoleRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new UserSignInHistoryRepository(
                                 AzureTableStorage <UserSignInHistoryEntity> .Create(userConString, "UserSignInHistory", c.Resolve <ILogFactory>())))
            .As <IUserSignInHistoryRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new TokensRepository(
                                 AzureTableStorage <TokenEntity> .Create(conString, "Tokens", c.Resolve <ILogFactory>())))
            .As <ITokensRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new KeyValuesRepository(
                                 AzureTableStorage <KeyValueEntity> .Create(conString, "KeyValues", c.Resolve <ILogFactory>()),
                                 c.Resolve <IKeyValueHistoryRepository>()))
            .As <IKeyValuesRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new KeyValuesRepository(
                                 AzureTableStorage <KeyValueEntity> .Create(secretsConString, "SecretKeyValues", c.Resolve <ILogFactory>()),
                                 c.Resolve <IKeyValueHistoryRepository>()))
            .As <ISecretKeyValuesRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new LockRepository(AzureTableStorage <LockEntity> .Create(conString, "Lock", c.Resolve <ILogFactory>())))
            .As <ILockRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new AccountTokenHistoryRepository(
                                 AzureTableStorage <AccountTokenHistoryEntity> .Create(conString, "AccessTokenHistory", c.Resolve <ILogFactory>())))
            .As <IAccountTokenHistoryRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new ServiceTokenHistoryRepository(
                                 AzureTableStorage <ServiceTokenHistoryEntity> .Create(conString, "ServiceTokenHistory", c.Resolve <ILogFactory>())))
            .As <IServiceTokenHistoryRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new RepositoriesRepository(
                                 AzureTableStorage <RepositoryEntity> .Create(conString, "Repositories", c.Resolve <ILogFactory>())))
            .As <IRepositoriesRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new ConnectionUrlHistoryRepository(
                                 AzureTableStorage <ConnectionUrlHistory> .Create(conString, "ConnectionUrlHistory", c.Resolve <ILogFactory>())))
            .As <IConnectionUrlHistoryRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new RepositoriesUpdateHistoryRepository(
                                 AzureTableStorage <RepositoryUpdateHistoryEntity> .Create(conString, "RepositoryUpdateHistory", c.Resolve <ILogFactory>())))
            .As <IRepositoriesUpdateHistoryRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new NetworkRepository(
                                 AzureTableStorage <NetworkEntity> .Create(conString, "Networks", c.Resolve <ILogFactory>())))
            .As <INetworkRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new UserActionHistoryRepository(
                                 AzureTableStorage <UserActionHistoryEntity> .Create(userConString, "UserActionHistory", c.Resolve <ILogFactory>()),
                                 new AzureBlobStorage(userConString.CurrentValue), "useractionhistoryparam"))
            .As <IUserActionHistoryRepository>()
            .SingleInstance();

            builder.Register(c =>
                             new KeyValueHistoryRepository(
                                 AzureTableStorage <KeyValueHistory> .Create(conString, "KeyValueHistory", c.Resolve <ILogFactory>()),
                                 new AzureBlobStorage(conString.CurrentValue), "keyvaluehistory"))
            .As <IKeyValueHistoryRepository>()
            .SingleInstance();

            builder.RegisterInstance(
                new RepositoryDataRepository(new AzureBlobStorage(conString.CurrentValue), "settings", "history")
                ).As <IRepositoryDataRepository>().SingleInstance();

            builder.RegisterInstance(
                new JsonDataRepository(new AzureBlobStorage(conString.CurrentValue), "settings", "history", "generalsettings.json")
                ).As <IJsonDataRepository>().SingleInstance();

            builder.RegisterInstance(
                new AccessDataRepository(new AzureBlobStorage(conString.CurrentValue), "access", "accesshistory", "accessHistory.json")
                ).As <IAccessDataRepository>().SingleInstance();
        }
コード例 #13
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.Converters.Add(new StringEnumConverter());
                    options.SerializerSettings.ContractResolver = new DefaultContractResolver();
                });

                services.AddSwaggerGen(options => { options.DefaultLykkeConfiguration(ApiVersion, ApiName); });

                var settingsManager = Configuration.LoadSettings <AppSettings>(options =>
                {
                    options.SetConnString(x => x.SlackNotifications.AzureQueue.ConnectionString);
                    options.SetQueueName(x => x.SlackNotifications.AzureQueue.QueueName);
                    options.SenderName = $"{AppEnvironment.Name} {AppEnvironment.Version}";
                });

                var appSettings = settingsManager.CurrentValue;
                if (appSettings.MonitoringServiceClient != null)
                {
                    _monitoringServiceUrl = appSettings.MonitoringServiceClient.MonitoringServiceUrl;
                }
                services.AddLykkeLogging(
                    settingsManager.ConnectionString(s => s.Bitcoin.Db.LogsConnString),
                    "BitcoinJobLog",
                    appSettings.SlackNotifications.AzureQueue.ConnectionString,
                    appSettings.SlackNotifications.AzureQueue.QueueName,
                    logging =>
                {
                    logging.AddAdditionalSlackChannel("BlockChainIntegration");
                    logging.AddAdditionalSlackChannel("BlockChainIntegrationImportantMessages",
                                                      options => { options.MinLogLevel = LogLevel.Warning; });
                });

                var builder = new ContainerBuilder();
                builder.Populate(services);

                builder.RegisterModule(new BitcoinJobModule(settingsManager));
                builder.RegisterModule(new RepositoryModule(settingsManager));
                builder.RegisterModule(new ServiceModule(settingsManager));

                ApplicationContainer = builder.Build();

                var logFactory = ApplicationContainer.Resolve <ILogFactory>();
                _log            = logFactory.CreateLog(this);
                _healthNotifier = ApplicationContainer.Resolve <IHealthNotifier>();

                var provider = new AnnotationsBasedMetamodelProvider();
                EntityMetamodel.Configure(provider);

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                if (_log == null)
                {
                    Console.WriteLine(ex);
                }
                else
                {
                    _log.Critical(ex);
                }
                throw;
            }
        }
コード例 #14
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver =
                        new Newtonsoft.Json.Serialization.DefaultContractResolver();
                });

                services.AddSwaggerGen(opt => opt.DefaultLykkeConfiguration("v1", "PayInternal API"));

                EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

                var builder = new ContainerBuilder();

                var appSettings = Configuration.LoadSettings <AppSettings>(options =>
                {
                    options.SetConnString(x => x.SlackNotifications.AzureQueue.ConnectionString);
                    options.SetQueueName(x => x.SlackNotifications.AzureQueue.QueueName);
                    options.SenderName = "PayInternal API";
                });

                _monitoringServiceUrl = appSettings.CurrentValue.MonitoringServiceClient?.MonitoringServiceUrl;

                services.AddLykkeLogging(
                    appSettings.ConnectionString(x => x.PayInternalService.Db.LogsConnString),
                    "PayInternalLog",
                    appSettings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString,
                    appSettings.CurrentValue.SlackNotifications.AzureQueue.QueueName);

                builder.RegisterModule(new AzureRepositories.AutofacModule(
                                           appSettings.Nested(o => o.PayInternalService.Db.MerchantOrderConnString),
                                           appSettings.Nested(o => o.PayInternalService.Db.MerchantConnString),
                                           appSettings.Nested(o => o.PayInternalService.Db.PaymentRequestConnString),
                                           appSettings.Nested(o => o.PayInternalService.Db.TransferConnString)));

                builder.RegisterModule(new Services.AutofacModule(
                                           appSettings.CurrentValue.PayInternalService.ExpirationPeriods,
                                           appSettings.CurrentValue.PayInternalService.TransactionConfirmationCount,
                                           appSettings.CurrentValue.PayInternalService.Blockchain.WalletAllocationPolicy.Policies,
                                           appSettings.CurrentValue.PayInternalService.AssetPairsLocalStorage.AssetPairs,
                                           appSettings.CurrentValue.PayInternalService.CacheSettings,
                                           appSettings.CurrentValue.PayInternalService.RetryPolicy));

                builder.RegisterModule(new ServiceModule(appSettings));
                builder.RegisterModule(new CqrsModule(appSettings));

                builder.Populate(services);

                ApplicationContainer = builder.Build();

                Log = ApplicationContainer.Resolve <ILogFactory>().CreateLog(this);

                HealthNotifier = ApplicationContainer.Resolve <IHealthNotifier>();

                Mapper.Initialize(cfg =>
                {
                    cfg.ConstructServicesUsing(ApplicationContainer.Resolve);
                    cfg.AddProfiles(typeof(AutoMapperProfile));
                    cfg.AddProfiles(typeof(AzureRepositories.AutoMapperProfile));
                    cfg.AddProfiles(typeof(Services.AutoMapperProfile));
                });

                Mapper.AssertConfigurationIsValid();

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                Log?.Critical(ex);
                throw;
            }
        }
コード例 #15
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                var appSettings = Configuration.Get <AppSettings>();

                services.AddAuthentication(opts =>
                {
                    opts.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    opts.DefaultChallengeScheme    = CookieAuthenticationDefaults.AuthenticationScheme;
                })
                .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
                {
                    o.LoginPath      = new PathString("/Account/SignIn");
                    o.ExpireTimeSpan = TimeSpan.FromMinutes(int.Parse(Configuration["UserLoginTime"]));
                });

                services.AddAuthorization(options =>
                {
                    options.DefaultPolicy = new AuthorizationPolicyBuilder(CookieAuthenticationDefaults.AuthenticationScheme).RequireAuthenticatedUser().Build();
                });

                services.AddMemoryCache();

                services.AddMvc();

                services.AddSwaggerGen(options =>
                {
                    options.DefaultLykkeConfiguration("v1", "SettingsServiceV2 API");
                    options.OperationFilter <ApiKeyHeaderOperationFilter>();
                });

                var builder = new ContainerBuilder();

                var settings = ConstantReloadingManager.From(appSettings);

                services.AddLykkeLogging(
                    settings.ConnectionString(x => x.ConnectionString),
                    "SettingsServiceLog",
                    appSettings.SlackNotificationsConnString,
                    appSettings.SlackNotificationsQueueName
                    );

                builder.RegisterModule(new AppModule(settings));
                builder.RegisterModule(new DbModule(settings));
                //builder.RegisterModule(new RabbitModule(settings, Log, _consoleLogger));
                builder.Populate(services);

                var provider = new AnnotationsBasedMetamodelProvider();
                EntityMetamodel.Configure(provider);

                ApplicationContainer = builder.Build();

                Log            = ApplicationContainer.Resolve <ILogFactory>().CreateLog(this);
                HealthNotifier = ApplicationContainer.Resolve <IHealthNotifier>();

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                Log?.Critical(ex);
                throw;
            }
        }
コード例 #16
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.AddHttpClient();
                services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver =
                        new Newtonsoft.Json.Serialization.DefaultContractResolver();
                });

                services.AddSwaggerGen(options =>
                {
                    options.DefaultLykkeConfiguration("v1", "JobStellarApi API");
                });

                EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

                var builder     = new ContainerBuilder();
                var appSettings = Configuration.LoadSettings <AppSettings>(options =>
                {
                    options.SetConnString(x => x.SlackNotifications.AzureQueue.ConnectionString);
                    options.SetQueueName(x => x.SlackNotifications.AzureQueue.QueueName);
                    options.SenderName = AppEnvironment.Name;
                });

                services.AddSingleton <Lykke.Service.Stellar.Api.Core.Settings.AppSettings>(appSettings.CurrentValue);

                services.AddLykkeLogging(
                    appSettings.ConnectionString(x => x.StellarApiService.Db.LogsConnString),
                    "JobStellarApiLog",
                    appSettings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString,
                    appSettings.CurrentValue.SlackNotifications.AzureQueue.QueueName,
                    logBuilder =>
                {
                    logBuilder.AddAdditionalSlackChannel("BlockChainIntegration", options =>
                    {
                        options.MinLogLevel = Microsoft.Extensions.Logging.LogLevel.Information;     // Let it be explicit
                    });

                    logBuilder.AddAdditionalSlackChannel("BlockChainIntegrationImportantMessages", options =>
                    {
                        options.MinLogLevel = Microsoft.Extensions.Logging.LogLevel.Warning;
                    });
                }
                    );

                builder.RegisterChaosKitty(appSettings.CurrentValue.StellarApiService.ChaosKitty);
                builder.RegisterModule(new StellarJobModule(appSettings.Nested(x => x.StellarApiJob)));
                builder.RegisterModule(new RepositoryModule(appSettings.Nested(x => x.StellarApiService)));
                builder.RegisterModule(new ServiceModule(appSettings.Nested(x => x.StellarApiService)));
                builder.Populate(services);

                ApplicationContainer = builder.Build();

                Log            = ApplicationContainer.Resolve <ILogFactory>().CreateLog(this);
                HealthNotifier = ApplicationContainer.Resolve <IHealthNotifier>();

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                Log?.Critical(ex);
                throw;
            }
        }
コード例 #17
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            Mapper.Initialize(x => x.AddProfile(typeof(AutoMapperProfile)));
            services.AddSingleton(Mapper.Instance);

            var conventionProvider = new ConventionBasedMetamodelProvider()
                                     .AddTypeValueTypesMergingStrategyRule(
                t => true,
                ValueTypeMergingStrategy.Forbid);

            var provider = new CompositeMetamodelProvider()
                           .AddProvider(new AnnotationsBasedMetamodelProvider())
                           .AddProvider(conventionProvider);

            EntityMetamodel.Configure(provider);

            return(services.BuildServiceProvider <AppSettings>(options =>
            {
                options.SwaggerOptions = _swaggerOptions;

                options.Logs = logs =>
                {
                    logs.AzureTableName = "KycSpiderLog";
                    logs.AzureTableConnectionStringResolver = settings => settings.KycSpiderService.Db.LogsConnection.ConnectionString;

                    // TODO: You could add extended logging configuration here:

                    /*
                     * logs.Extended = extendedLogs =>
                     * {
                     *  // For example, you could add additional slack channel like this:
                     *  extendedLogs.AddAdditionalSlackChannel("KycSpider", channelOptions =>
                     *  {
                     *      channelOptions.MinLogLevel = LogLevel.Information;
                     *  });
                     * };
                     */
                };

                // TODO: Extend the service configuration

                /*
                 * options.Extend = (sc, settings) =>
                 * {
                 *  sc
                 *      .AddOptions()
                 *      .AddAuthentication(MyAuthOptions.AuthenticationScheme)
                 *      .AddScheme<MyAuthOptions, KeyAuthHandler>(MyAuthOptions.AuthenticationScheme, null);
                 * };
                 */

                // TODO: You could add extended Swagger configuration here:

                /*
                 * options.Swagger = swagger =>
                 * {
                 *  swagger.IgnoreObsoleteActions();
                 * };
                 */
            }));
        }
コード例 #18
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            try
            {
                services.AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver =
                        new Newtonsoft.Json.Serialization.DefaultContractResolver();
                });

                services.AddSwaggerGen(options =>
                {
                    options.SwaggerDoc(
                        "v1",
                        new Info
                    {
                        Version = "v1",
                        Title   = "Lykke.Service.PayInvoice API"
                    });

                    options.DescribeAllEnumsAsStrings();
                    options.EnableXmsEnumExtension();
                    options.EnableXmlDocumentation();

                    options.OperationFilter <FileUploadOperation>();
                });

                EntityMetamodel.Configure(new AnnotationsBasedMetamodelProvider());

                Mapper.Initialize(cfg =>
                {
                    cfg.AddProfiles(typeof(AutoMapperProfile));
                    cfg.AddProfiles(typeof(Services.AutoMapperProfile));
                    cfg.AddProfiles(typeof(Repositories.AutoMapperProfile));
                });

                Mapper.AssertConfigurationIsValid();

                var builder     = new ContainerBuilder();
                var appSettings = Configuration.LoadSettings <AppSettings>(options => {});
                if (appSettings.CurrentValue.MonitoringServiceClient != null)
                {
                    _monitoringServiceUrl = appSettings.CurrentValue.MonitoringServiceClient.MonitoringServiceUrl;
                }

                services.AddLykkeLogging(
                    appSettings.ConnectionString(x => x.PayInvoiceService.Db.LogsConnectionString),
                    "PayInvoiceLog",
                    appSettings.CurrentValue.SlackNotifications.AzureQueue.ConnectionString,
                    appSettings.CurrentValue.SlackNotifications.AzureQueue.QueueName);

                builder.RegisterModule(
                    new Repositories.AutofacModule(appSettings.Nested(o => o.PayInvoiceService.Db.DataConnectionString)));

                builder.RegisterModule(new Services.AutofacModule(
                                           appSettings.CurrentValue.PayInvoiceService.CacheExpirationPeriods,
                                           appSettings.CurrentValue.PayInvoiceService.DistributedCacheSettings,
                                           appSettings.CurrentValue.PayInvoiceService.RetryPolicy,
                                           appSettings.CurrentValue.PayInvoiceService.PayInvoicePortalUrl));

                builder.RegisterModule(new AutofacModule(appSettings));

                builder.RegisterModule(new CqrsModule(appSettings.Nested(x => x.PayInvoiceService.Cqrs)));

                builder.Populate(services);
                ApplicationContainer = builder.Build();

                Log = ApplicationContainer.Resolve <ILogFactory>().CreateLog(this);

                HealthNotifier = ApplicationContainer.Resolve <IHealthNotifier>();

                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                Log?.Critical(ex);
                throw;
            }
        }