Refactored database registration to allow postgres to use internal representations for afster performance
This commit is contained in:
@@ -8,8 +8,18 @@ public static class Postgres
|
||||
|
||||
public static IServiceCollection AddMidrandShopDatabase(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var connectionString = configuration.GetConnectionString(MidrandBooksDbConfigName);
|
||||
|
||||
var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString);
|
||||
|
||||
dataSourceBuilder.ConfigureTypeLoading(options => { options.EnableTypeLoading(false); });
|
||||
|
||||
var dataSource = dataSourceBuilder.Build();
|
||||
|
||||
services.AddSingleton(dataSource);
|
||||
|
||||
services.AddPooledDbContextFactory<MidrandBooksDbContext>(options =>
|
||||
options.UseNpgsql(configuration.GetConnectionString(MidrandBooksDbConfigName)));
|
||||
options.UseNpgsql(dataSource));
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -4,19 +4,15 @@ namespace LiteCharms.Features.MidrandBooks.Extensions;
|
||||
|
||||
public static class Shop
|
||||
{
|
||||
public static IServiceCollection AddShopServices(this IServiceCollection services, Assembly assembly, ServiceLifetime serviceLifetime)
|
||||
public static IServiceCollection AddShopServices(this IServiceCollection services)
|
||||
{
|
||||
var serviceType = typeof(IService);
|
||||
|
||||
var implementations = assembly.GetTypes()
|
||||
var implementations = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => serviceType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract);
|
||||
|
||||
foreach (var implementation in implementations)
|
||||
{
|
||||
var descriptor = new ServiceDescriptor(serviceType, implementation, serviceLifetime);
|
||||
|
||||
services.Add(descriptor);
|
||||
}
|
||||
foreach (var implementation in implementations)
|
||||
services.AddScoped(implementation);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user