Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ClemBotContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ClemBot.Api 1.0.0"));
            }
            app.UseSerilogRequestLogging();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints => endpoints.MapControllers());

            // Apply any new migrations
            context.Database.Migrate();

            // Load linq2db for bulk copies
            LinqToDBForEFTools.Initialize();


            // Reload enum types after a migration
            using var conn = (NpgsqlConnection)context.Database.GetDbConnection();
            conn.Open();
            conn.ReloadTypes();
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            LinqToDBForEFTools.Initialize();
            var connStr = "Host=localhost;Port=5432;Database=stub_db;Username=stub_user;Password=stub_password";

            base.OnConfiguring(optionsBuilder.UseNpgsql(connStr));
        }
Exemplo n.º 3
0
        private async Task <string> ProcessAsync(string s3BucketName, string s3ObjectKey)
        {
            var apiServerLogKeyword       = Environment.GetEnvironmentVariable("apiServerLogKeyword");
            var dedicatedServerLogKeyword = Environment.GetEnvironmentVariable("dedicatedServerLogKeyword");

            if (!s3ObjectKey.ToLower().Contains(apiServerLogKeyword) &&
                !s3ObjectKey.ToLower().Contains(dedicatedServerLogKeyword))
            {
                return(string.Empty);
            }

            var readCount    = 0;
            var processCount = 0;
            var insertCount  = 0;

            var sw = Stopwatch.StartNew();

            LinqToDBForEFTools.Initialize();

            var optBuilder = new LinqToDbConnectionOptionsBuilder();

            optBuilder.UseMySql(GetConnectionString());

            using (var dataConnection = new DataConnection(optBuilder.Build()))
            {
                // todo: 1つのeventに2つ以上のファイルが含まれることがないか確認する
                var request = new GetObjectRequest
                {
                    BucketName = s3BucketName,
                    Key        = s3ObjectKey,
                };

                using (var getResponse = await S3Client.GetObjectAsync(request))
                    using (var streamReader = new StreamReader(getResponse.ResponseStream))
                        using (var tran = dataConnection.BeginTransaction())
                        {
                            try
                            {
                                if (s3ObjectKey.ToLower().Contains(apiServerLogKeyword))
                                {
                                    (readCount, processCount, insertCount) = await new ApiServerLogProcessor(dataConnection).ProcessAsync(streamReader);
                                }
                                else if (s3ObjectKey.ToLower().Contains(dedicatedServerLogKeyword))
                                {
                                    (readCount, processCount, insertCount) = await new DedicatedServerLogProcessor(dataConnection).ProcessAsync(streamReader);
                                }

                                tran.Commit();
                            }
                            catch
                            {
                                tran.Rollback();
                                throw;
                            }
                        }

                return($"{sw.Elapsed.TotalMilliseconds:N0} msec. read: {readCount:N0} lines. process: {processCount:N0} lines. insert: {insertCount:N0} rows.");
            }
        }
Exemplo n.º 4
0
 public BaseNativeTests(NativeDbContext dbContext)
 {
     DbContext = dbContext;
     LinqToDBForEFTools.Initialize();
     InitializeDbContext();
     ClearTables();
     CreateUser();
 }
Exemplo n.º 5
0
        public void EnsureCreatedAndConnectedWithLinq2Db(ITestOutputHelper output)
        {
            Database.OpenConnection();
            Database.EnsureCreated();

            // Linq2Db
            LinqToDBForEFTools.Initialize();
        }
        public void TestJsonConvert()
        {
            LinqToDBForEFTools.Initialize();

            // // converting from string, because usually JSON is stored as string, but it depends on DataProvider
            // Mapping.MappingSchema.Default.SetConverter<string, LocalizedString>(v => JsonConvert.DeserializeObject<LocalizedString>(v));
            //
            // // here we told linq2db how to pass converted value as DataParameter.
            // Mapping.MappingSchema.Default.SetConverter<LocalizedString, DataParameter>(v => new DataParameter("", JsonConvert.SerializeObject(v), LinqToDB.DataType.NVarChar));

            using (var ctx = new JsonConvertContext(_options))
            {
                ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();

                ctx.EventScheduleItems.Delete();

                ctx.EventScheduleItems.Add(new EventScheduleItem()
                {
                    NameLocalized = new LocalizedString()
                    {
                        English = "English", German = "German", Slovak = "Slovak"
                    },
                    GuidColumn = Guid.NewGuid()
                });
                ctx.SaveChanges();

                var queryable = ctx.EventScheduleItems
                                .Where(p => p.Id < 10).ToLinqToDB();

                var path = "some";

                var items = queryable
                            .Select(p => new
                {
                    p.Id,
                    p.NameLocalized,
                    p.CrashEnum,
                    p.GuidColumn,
                    JsonValue = JsonValue(p.JsonColumn, path)
                });

                var item = items.FirstOrDefault();

                Assert.That(item.NameLocalized.English, Is.EqualTo("English"));
                Assert.That(item.NameLocalized.German, Is.EqualTo("German"));
                Assert.That(item.NameLocalized.Slovak, Is.EqualTo("Slovak"));

                //TODO: make it work
                // var concrete = queryable.Select(p => new
                // {
                //  p.Id,
                //  English = p.NameLocalized.English
                // }).FirstOrDefault();
                //
                // Assert.That(concrete.English, Is.EqualTo("English"));
            }
        }
        public static void AddEFRepositories(this IServiceCollection services, bool selfHosted, string connectionString,
                                             SupportedDatabaseProviders provider)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception($"Database provider type {provider} was selected but no connection string was found.");
            }
            LinqToDBForEFTools.Initialize();
            services.AddAutoMapper(typeof(UserRepository));
            services.AddDbContext <DatabaseContext>(options =>
            {
                if (provider == SupportedDatabaseProviders.Postgres)
                {
                    options.UseNpgsql(connectionString);
                    // Handle NpgSql Legacy Support for `timestamp without timezone` issue
                    AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
                }
                else if (provider == SupportedDatabaseProviders.MySql)
                {
                    options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
                }
            });
            services.AddSingleton <ICipherRepository, CipherRepository>();
            services.AddSingleton <ICollectionCipherRepository, CollectionCipherRepository>();
            services.AddSingleton <ICollectionRepository, CollectionRepository>();
            services.AddSingleton <IDeviceRepository, DeviceRepository>();
            services.AddSingleton <IEmergencyAccessRepository, EmergencyAccessRepository>();
            services.AddSingleton <IFolderRepository, FolderRepository>();
            services.AddSingleton <IGrantRepository, GrantRepository>();
            services.AddSingleton <IGroupRepository, GroupRepository>();
            services.AddSingleton <IInstallationRepository, InstallationRepository>();
            services.AddSingleton <IMaintenanceRepository, MaintenanceRepository>();
            services.AddSingleton <IOrganizationRepository, OrganizationRepository>();
            services.AddSingleton <IOrganizationApiKeyRepository, OrganizationApiKeyRepository>();
            services.AddSingleton <IOrganizationConnectionRepository, OrganizationConnectionRepository>();
            services.AddSingleton <IOrganizationSponsorshipRepository, OrganizationSponsorshipRepository>();
            services.AddSingleton <IOrganizationUserRepository, OrganizationUserRepository>();
            services.AddSingleton <IPolicyRepository, PolicyRepository>();
            services.AddSingleton <ISendRepository, SendRepository>();
            services.AddSingleton <ISsoConfigRepository, SsoConfigRepository>();
            services.AddSingleton <ISsoUserRepository, SsoUserRepository>();
            services.AddSingleton <ITaxRateRepository, TaxRateRepository>();
            services.AddSingleton <ITransactionRepository, TransactionRepository>();
            services.AddSingleton <IUserRepository, UserRepository>();
            services.AddSingleton <IProviderRepository, ProviderRepository>();
            services.AddSingleton <IProviderUserRepository, ProviderUserRepository>();
            services.AddSingleton <IProviderOrganizationRepository, ProviderOrganizationRepository>();

            if (selfHosted)
            {
                services.AddSingleton <IEventRepository, EventRepository>();
            }
        }
Exemplo n.º 8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            string connection = configuration.GetConnectionString("DefaultConnection");

            services
            .AddEntityFrameworkNpgsql()
            .AddDbContext <IssueContext>(options =>
                                         options.UseNpgsql(connection)
                                         );

            LinqToDBForEFTools.Initialize();
        }
Exemplo n.º 9
0
        public void TestIdentityColumn()
        {
            using (var ctx = CreateAdventureWorksContext())
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model);

                var identity = ms.GetAttribute <ColumnAttribute>(typeof(SalesOrderDetail),
                                                                 MemberHelper.MemberOf <SalesOrderDetail>(c => c.SalesOrderDetailID));

                Assert.NotNull(identity);
                Assert.AreEqual(true, identity.IsIdentity);
            }
        }
Exemplo n.º 10
0
        public void TestStringMappings()
        {
            using (var db = CreateContext())
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(db.Model, db);
                var ed = ms.GetEntityDescriptor(typeof(StringTypes));

                ed.Columns.First(c => c.MemberName == nameof(StringTypes.AnsiString)).DataType.Should()
                .Be(DataType.VarChar);

                ed.Columns.First(c => c.MemberName == nameof(StringTypes.UnicodeString)).DataType.Should()
                .Be(DataType.NVarChar);
            }
        }
Exemplo n.º 11
0
        public void TestKey()
        {
            using (var ctx = CreateContext(false))
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, ctx);

                var customerPk = ms.GetAttribute <ColumnAttribute>(typeof(Customer),
                                                                   MemberHelper.MemberOf <Customer>(c => c.CustomerId));

                Assert.NotNull(customerPk);
                Assert.AreEqual(true, customerPk !.IsPrimaryKey);
                Assert.AreEqual(0, customerPk.PrimaryKeyOrder);
            }
        }
Exemplo n.º 12
0
        public void TestAssociations()
        {
            using (var ctx = CreateContext(false))
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, ctx);

                var associationOrder = ms.GetAttribute <AssociationAttribute>(typeof(Customer),
                                                                              MemberHelper.MemberOf <Customer>(c => c.Orders));

                Assert.NotNull(associationOrder);
                Assert.That(associationOrder !.ThisKey, Is.EqualTo("CustomerId"));
                Assert.That(associationOrder.OtherKey, Is.EqualTo("CustomerId"));
            }
        }
Exemplo n.º 13
0
        public EntityUpdateTest()
        {
            //       System.Diagnostics.DiagnosticListener.AllListeners.Subscribe(new CommandListener());
            LinqToDBForEFTools.Initialize();

            //BatchUpdateManager.BatchUpdateBuilder = builder =>
            //{
            //    builder.Executing = (command) =>
            //    {
            //        Trace.TraceInformation("\r\n执行时间:{0} 毫秒 \r\n -->CommandExecuted.Command:\r\n{1}\r\nParamter:{2}", "", command.CommandText,
            //           string.Join(",", command.Parameters.Cast<IDbDataParameter>().Select(t => string.Format("{0}:{1}:{2};", t.ParameterName, t.DbType, t.Value)))
            //           );
            //    };

            //};
        }
        public void TestIdentityColumn()
        {
            using (var ctx = CreateContext())
            {
                var dependencies  = ctx.GetService <RelationalSqlTranslatingExpressionVisitorDependencies>();
                var mappingSource = ctx.GetService <IRelationalTypeMappingSource>();
                var converters    = ctx.GetService <IValueConverterSelector>();
                var ms            = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, mappingSource);

                var identity = ms.GetAttribute <ColumnAttribute>(typeof(Customer),
                                                                 MemberHelper.MemberOf <Customer>(c => c.CustomerId));

                //TODO:
                //Assert.NotNull(identity);
                //Assert.AreEqual(true, identity.IsIdentity);
            }
        }
        public void TestAssociations()
        {
            using (var ctx = CreateContext())
            {
                var dependencies  = ctx.GetService <RelationalSqlTranslatingExpressionVisitorDependencies>();
                var mappingSource = ctx.GetService <IRelationalTypeMappingSource>();
                var converters    = ctx.GetService <IValueConverterSelector>();
                var ms            = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, null);

                var associationOrder = ms.GetAttribute <AssociationAttribute>(typeof(Customer),
                                                                              MemberHelper.MemberOf <Customer>(c => c.Orders));

                Assert.NotNull(associationOrder);
                Assert.That(associationOrder.ThisKey, Is.EqualTo("CustomerId"));
                Assert.That(associationOrder.OtherKey, Is.EqualTo("CustomerId"));
            }
        }
Exemplo n.º 16
0
        public void TestKey()
        {
            using (var ctx = CreateContext(false))
            {
                var dependencies  = ctx.GetService <RelationalSqlTranslatingExpressionVisitorDependencies>();
                var mappingSource = ctx.GetService <IRelationalTypeMappingSource>();
                var converters    = ctx.GetService <IValueConverterSelector>();
                var ms            = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, mappingSource);

                var customerPk = ms.GetAttribute <ColumnAttribute>(typeof(Customer),
                                                                   MemberHelper.MemberOf <Customer>(c => c.CustomerId));

                Assert.NotNull(customerPk);
                Assert.AreEqual(true, customerPk.IsPrimaryKey);
                Assert.AreEqual(0, customerPk.PrimaryKeyOrder);
            }
        }
Exemplo n.º 17
0
        public NadekoBot(int shardId, int parentProcessId)
        {
            if (shardId < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(shardId));
            }

            LogSetup.SetupLogger(shardId);
            TerribleElevatedPermissionCheck();

            Credentials = new BotCredentials();
            Cache       = new RedisCache(Credentials, shardId);
            LinqToDBForEFTools.Initialize();
            _db = new DbService(Credentials);

            if (shardId == 0)
            {
                _db.Setup();
            }

            Client = new DiscordSocketClient(new DiscordSocketConfig
            {
                MessageCacheSize    = 50,
                LogLevel            = LogSeverity.Warning,
                ConnectionTimeout   = int.MaxValue,
                TotalShards         = Credentials.TotalShards,
                ShardId             = shardId,
                AlwaysDownloadUsers = false,
                ExclusiveBulkDelete = true,
            });

            CommandService = new CommandService(new CommandServiceConfig()
            {
                CaseSensitiveCommands = false,
                DefaultRunMode        = RunMode.Sync,
            });

            SetupShard(parentProcessId);

#if GLOBAL_NADEKO || DEBUG
            Client.Log += Client_Log;
#endif
        }
Exemplo n.º 18
0
        public void TestCompositeKey()
        {
            using (var ctx = CreateAdventureWorksContext())
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model);

                var customerPk = ms.GetAttribute <ColumnAttribute>(typeof(CustomerAddress),
                                                                   MemberHelper.MemberOf <CustomerAddress>(c => c.CustomerID));

                Assert.NotNull(customerPk);
                Assert.AreEqual(true, customerPk.IsPrimaryKey);
                Assert.AreEqual(0, customerPk.PrimaryKeyOrder);

                var addressPk = ms.GetAttribute <ColumnAttribute>(typeof(CustomerAddress),
                                                                  MemberHelper.MemberOf <CustomerAddress>(c => c.AddressID));

                Assert.NotNull(addressPk);
                Assert.AreEqual(true, addressPk.IsPrimaryKey);
                Assert.AreEqual(1, addressPk.PrimaryKeyOrder);
            }
        }
Exemplo n.º 19
0
        public void TestAssociations()
        {
            using (var ctx = CreateAdventureWorksContext())
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model);

                var associationCustomer = ms.GetAttribute <AssociationAttribute>(typeof(CustomerAddress),
                                                                                 MemberHelper.MemberOf <CustomerAddress>(c => c.Customer));

                Assert.NotNull(associationCustomer);
                Assert.AreEqual("CustomerID", associationCustomer.ThisKey);
                Assert.AreEqual("CustomerID", associationCustomer.OtherKey);

                var associationAddress = ms.GetAttribute <AssociationAttribute>(typeof(CustomerAddress),
                                                                                MemberHelper.MemberOf <CustomerAddress>(c => c.Address));

                Assert.NotNull(associationAddress);
                Assert.AreEqual("AddressID", associationAddress.ThisKey);
                Assert.AreEqual("AddressID", associationAddress.OtherKey);
            }
        }
Exemplo n.º 20
0
        public override void PreInitialize()
        {
            //System.Diagnostics.DiagnosticListener.AllListeners.Subscribe(new CommandListener());
            LinqToDBForEFTools.Initialize();
            //BatchUpdateManager.BatchUpdateBuilder = builder =>
            //{
            //    builder.Executing = (command) =>
            //    {
            //        Trace.TraceInformation("\r\n执行时间:{0} 毫秒 \r\n -->CommandExecuted.Command:\r\n{1}\r\nParamter:{2}", "", command.CommandText,
            //           string.Join(",", command.Parameters.Cast<IDbDataParameter>().Select(t => string.Format("{0}:{1}:{2};", t.ParameterName, t.DbType, t.Value)))
            //           );
            //    };

            //};

            // Database.SetInitializer<BaseBlocksDbContext>(null);
            // Configuration.ReplaceService<IEfTransactionStrategy, DefaultTransactionStrategy>(DependencyLifeStyle.Transient);

            //#if DEBUG //TODO
            //            DbInterception.Add(new EFIntercepterLogging());
            //#endif
        }
Exemplo n.º 21
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            LinqToDBForEFTools.Initialize();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <AppDbContext>();
                    DbInitializer.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
Exemplo n.º 22
0
 public Linq2DbProvider(ILogger <Linq2DbProvider> logger)
 {
     LinqToDBForEFTools.Initialize();
     DataConnection.TurnTraceSwitchOn();
     DataConnection.WriteTraceLine = (msg, category, level) => logger.Log(GetLogLevel(level), msg);
 }
Exemplo n.º 23
0
 static NpgSqlTests()
 {
     LinqToDBForEFTools.Initialize();
     DataConnection.TurnTraceSwitchOn();
 }
        public static void AddSqlServerRepositories(this IServiceCollection services, GlobalSettings globalSettings)
        {
            var selectedDatabaseProvider = globalSettings.DatabaseProvider;
            var provider         = SupportedDatabaseProviders.SqlServer;
            var connectionString = string.Empty;

            if (!string.IsNullOrWhiteSpace(selectedDatabaseProvider))
            {
                switch (selectedDatabaseProvider.ToLowerInvariant())
                {
                case "postgres":
                case "postgresql":
                    provider         = SupportedDatabaseProviders.Postgres;
                    connectionString = globalSettings.PostgreSql.ConnectionString;
                    break;

                case "mysql":
                case "mariadb":
                    provider         = SupportedDatabaseProviders.MySql;
                    connectionString = globalSettings.MySql.ConnectionString;
                    break;

                default:
                    break;
                }
            }

            var useEf = (provider != SupportedDatabaseProviders.SqlServer);

            if (useEf)
            {
                if (string.IsNullOrWhiteSpace(connectionString))
                {
                    throw new Exception($"Database provider type {provider} was selected but no connection string was found.");
                }
                LinqToDBForEFTools.Initialize();
                services.AddAutoMapper(typeof(EntityFrameworkRepos.UserRepository));
                services.AddDbContext <EntityFrameworkRepos.DatabaseContext>(options =>
                {
                    if (provider == SupportedDatabaseProviders.Postgres)
                    {
                        options.UseNpgsql(connectionString);
                    }
                    else if (provider == SupportedDatabaseProviders.MySql)
                    {
                        options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
                    }
                });
                services.AddSingleton <ICipherRepository, EntityFrameworkRepos.CipherRepository>();
                services.AddSingleton <ICollectionCipherRepository, EntityFrameworkRepos.CollectionCipherRepository>();
                services.AddSingleton <ICollectionRepository, EntityFrameworkRepos.CollectionRepository>();
                services.AddSingleton <IDeviceRepository, EntityFrameworkRepos.DeviceRepository>();
                services.AddSingleton <IEmergencyAccessRepository, EntityFrameworkRepos.EmergencyAccessRepository>();
                services.AddSingleton <IFolderRepository, EntityFrameworkRepos.FolderRepository>();
                services.AddSingleton <IGrantRepository, EntityFrameworkRepos.GrantRepository>();
                services.AddSingleton <IGroupRepository, EntityFrameworkRepos.GroupRepository>();
                services.AddSingleton <IInstallationRepository, EntityFrameworkRepos.InstallationRepository>();
                services.AddSingleton <IMaintenanceRepository, EntityFrameworkRepos.MaintenanceRepository>();
                services.AddSingleton <IOrganizationRepository, EntityFrameworkRepos.OrganizationRepository>();
                services.AddSingleton <IOrganizationUserRepository, EntityFrameworkRepos.OrganizationUserRepository>();
                services.AddSingleton <IPolicyRepository, EntityFrameworkRepos.PolicyRepository>();
                services.AddSingleton <ISendRepository, EntityFrameworkRepos.SendRepository>();
                services.AddSingleton <ISsoConfigRepository, EntityFrameworkRepos.SsoConfigRepository>();
                services.AddSingleton <ISsoUserRepository, EntityFrameworkRepos.SsoUserRepository>();
                services.AddSingleton <ITaxRateRepository, EntityFrameworkRepos.TaxRateRepository>();
                services.AddSingleton <ITransactionRepository, EntityFrameworkRepos.TransactionRepository>();
                services.AddSingleton <IU2fRepository, EntityFrameworkRepos.U2fRepository>();
                services.AddSingleton <IUserRepository, EntityFrameworkRepos.UserRepository>();
                services.AddSingleton <IProviderRepository, EntityFrameworkRepos.ProviderRepository>();
                services.AddSingleton <IProviderUserRepository, EntityFrameworkRepos.ProviderUserRepository>();
                services.AddSingleton <IProviderOrganizationRepository, EntityFrameworkRepos.ProviderOrganizationRepository>();
            }
            else
            {
                services.AddSingleton <ICipherRepository, SqlServerRepos.CipherRepository>();
                services.AddSingleton <ICollectionCipherRepository, SqlServerRepos.CollectionCipherRepository>();
                services.AddSingleton <ICollectionRepository, SqlServerRepos.CollectionRepository>();
                services.AddSingleton <IDeviceRepository, SqlServerRepos.DeviceRepository>();
                services.AddSingleton <IEmergencyAccessRepository, SqlServerRepos.EmergencyAccessRepository>();
                services.AddSingleton <IFolderRepository, SqlServerRepos.FolderRepository>();
                services.AddSingleton <IGrantRepository, SqlServerRepos.GrantRepository>();
                services.AddSingleton <IGroupRepository, SqlServerRepos.GroupRepository>();
                services.AddSingleton <IInstallationRepository, SqlServerRepos.InstallationRepository>();
                services.AddSingleton <IMaintenanceRepository, SqlServerRepos.MaintenanceRepository>();
                services.AddSingleton <IOrganizationRepository, SqlServerRepos.OrganizationRepository>();
                services.AddSingleton <IOrganizationUserRepository, SqlServerRepos.OrganizationUserRepository>();
                services.AddSingleton <IPolicyRepository, SqlServerRepos.PolicyRepository>();
                services.AddSingleton <ISendRepository, SqlServerRepos.SendRepository>();
                services.AddSingleton <ISsoConfigRepository, SqlServerRepos.SsoConfigRepository>();
                services.AddSingleton <ISsoUserRepository, SqlServerRepos.SsoUserRepository>();
                services.AddSingleton <ITaxRateRepository, SqlServerRepos.TaxRateRepository>();
                services.AddSingleton <IEmergencyAccessRepository, SqlServerRepos.EmergencyAccessRepository>();
                services.AddSingleton <IProviderRepository, SqlServerRepos.ProviderRepository>();
                services.AddSingleton <IProviderUserRepository, SqlServerRepos.ProviderUserRepository>();
                services.AddSingleton <IProviderOrganizationRepository, SqlServerRepos.ProviderOrganizationRepository>();
                services.AddSingleton <ITransactionRepository, SqlServerRepos.TransactionRepository>();
                services.AddSingleton <IU2fRepository, SqlServerRepos.U2fRepository>();
                services.AddSingleton <IUserRepository, SqlServerRepos.UserRepository>();
            }

            if (globalSettings.SelfHosted)
            {
                if (useEf)
                {
                    services.AddSingleton <IEventRepository, EntityFrameworkRepos.EventRepository>();
                }
                else
                {
                    services.AddSingleton <IEventRepository, SqlServerRepos.EventRepository>();
                }
                services.AddSingleton <IInstallationDeviceRepository, NoopRepos.InstallationDeviceRepository>();
                services.AddSingleton <IMetaDataRepository, NoopRepos.MetaDataRepository>();
            }
            else
            {
                services.AddSingleton <IEventRepository, TableStorageRepos.EventRepository>();
                services.AddSingleton <IInstallationDeviceRepository, TableStorageRepos.InstallationDeviceRepository>();
                services.AddSingleton <IMetaDataRepository, TableStorageRepos.MetaDataRepository>();
            }
        }