Пример #1
0
        public static IServices Create(IServiceDependencies dependencies)
        {
            IRepositories   repositories;
            IServiceContext context;

            if (!dependencies.UseTestRepositories)
            {
                repositories = RepositoriesFactory.Create(dependencies.RepositoriesConfig);
                context      = new ServiceContext(dependencies, repositories);

                // TODO -- Implement Integration Test Repositories/Services
                //if (dependencies.UseIntegrationTestRepositories)
                //{
                //    return new TestServices(context);
                //}
                //else
                //{
                //    return new Implementation.Services(context);
                //}
                return(new Implementation.Services(context));
            }
            else
            {
                // TODO -- Implement Test Repositories/Services
                //repositories = TestRepositoriesFactory.Create();
                //context = new ServiceContext(dependencies, repositories);
                //return new TestServices(context);

                repositories = RepositoriesFactory.Create(dependencies.RepositoriesConfig);
                context      = new ServiceContext(dependencies, repositories);
                return(new Implementation.Services(context));
            }
        }
        public async Task InitializeAsync(IServiceCollection serviceCollection, IConfiguration configuration, CancellationToken cancellationToken = default)
        {
            var connectionString = new PostgreSqlConnectionProvoder
            {
                DatabaseName   = configuration.GetValue <string>("Database:PostgreSql:DatabaseName"),
                Host           = configuration.GetValue <string>("Database:PostgreSql:Host"),
                Port           = configuration.GetValue <int>("Database:PostgreSql:Port"),
                UserName       = configuration.GetValue <string>("Database:PostgreSql:UserName"),
                Password       = configuration.GetValue <string>("Database:PostgreSql:Password"),
                CommandTimeout = configuration.GetValue <int>("Database:PostgreSql:CommandTimeout"),
            };
            var databaseProvider = new PostgreSqlDatabaseProvider(connectionString);
            var databaseService  = new DatabaseService(databaseProvider);

            serviceCollection.AddSingleton <IDatabaseService>(databaseService);
            serviceCollection.AddSingleton(RepositoriesFactory.Create <ICitiesRepository>(databaseService));
            serviceCollection.AddSingleton(RepositoriesFactory.Create <ICountriesRepository>(databaseService));
            serviceCollection.AddSingleton(RepositoriesFactory.Create <IContinentsRepository>(databaseService));
            serviceCollection.AddSingleton(RepositoriesFactory.Create <IIpV4ClientsRepository>(databaseService));
            serviceCollection.AddSingleton(RepositoriesFactory.Create <IIpV6ClientsRepository>(databaseService));
            serviceCollection.AddSingleton(RepositoriesFactory.Create <ILocationsRepository>(databaseService));

            await databaseProvider.CreateDatabaseAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
        }