Support generic DbContext in AddInfrastructureServices
Updated AddInfrastructureServices to support a generic TRecDbContext type parameter, enabling the use of custom DbContext types. Modified AddDbContext and AddDbRepository to use the generic TRecDbContext type. Added an overload of AddInfrastructureServices that defaults to RecDbContext for backward compatibility. These changes enhance flexibility and reusability while maintaining compatibility with existing implementations.
This commit is contained in:
parent
d902cfb756
commit
e552658d2e
@ -7,7 +7,8 @@ namespace ReC.Infrastructure;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action<ConfigurationOptions> options)
|
||||
public static IServiceCollection AddInfrastructureServices<TRecDbContext>(this IServiceCollection services, Action<ConfigurationOptions> options)
|
||||
where TRecDbContext : RecDbContext
|
||||
{
|
||||
var configOpt = new ConfigurationOptions();
|
||||
options.Invoke(configOpt);
|
||||
@ -17,11 +18,14 @@ public static class DependencyInjection
|
||||
|
||||
services.AddDbContext<RecDbContext>(configOpt.DbContextOptionsAction);
|
||||
|
||||
services.AddDbRepository(opt => opt.RegisterFromAssembly<RecDbContext>(typeof(RecAction).Assembly));
|
||||
services.AddDbRepository(opt => opt.RegisterFromAssembly<TRecDbContext>(typeof(RecAction).Assembly));
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action<ConfigurationOptions> options)
|
||||
=> services.AddInfrastructureServices<RecDbContext>(options);
|
||||
|
||||
public class ConfigurationOptions
|
||||
{
|
||||
internal Action<DbContextOptionsBuilder>? DbContextOptionsAction { get; private set; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user