-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepositoryServiceExtensions.cs
36 lines (34 loc) · 1.32 KB
/
RepositoryServiceExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public static class RepositoryServiceExtensions
{
public static void AddRepositoryServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddRepositoryServices(configuration, "DefaultConnection");
}
public static void AddRepositoryServices(this IServiceCollection services, IConfiguration configuration, string connectionStringName)
{
var dbType = configuration["Database"];
switch (dbType?.ToLower())
{
case "litedb":
services.AddLiteDbRepositories(connectionStringName);
break;
case "mongodb":
services.AddMongoDbRepositories(connectionStringName);
break;
case "sqlite":
services.AddSqliteRepositories(connectionStringName);
break;
case "sqlserver":
services.AddSqlServerRepositories(connectionStringName);
break;
case "mysql":
services.AddMySqlRepositories(connectionStringName);
break;
case "postgresql":
services.AddPostgresRepositories(connectionStringName);
break;
default:
throw new InvalidOperationException($"Unsupported database type: {dbType}");
}
}
}