feat(infrastructure): add DbSetFactory registration in DependencyInjection
- Introduced AddDbSetFactory to support DbSet factory registration for entities. - Updated RepositoryConfiguration.RegisterFromAssembly to register both repositories and DbSet factories. - Changed RegisterFromAssembly and RegisterEntity to void methods instead of fluent interface. - Extracted DbRepositoryFactory into its own Factory namespace for better separation of concerns.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure.Factory;
|
||||
|
||||
public class DbRepositoryFactory : IRepositoryFactory
|
||||
{
|
||||
private readonly IServiceProvider _provider;
|
||||
|
||||
public DbRepositoryFactory(IServiceProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
public IRepository<TEntity> Get<TEntity>() => _provider.GetRequiredService<IRepository<TEntity>>();
|
||||
}
|
||||
13
DigitalData.Core.Infrastructure/Factory/DbSetFactory.cs
Normal file
13
DigitalData.Core.Infrastructure/Factory/DbSetFactory.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure.Factory;
|
||||
|
||||
public class DbSetFactory<TDbContext,TEntity> where TDbContext : DbContext where TEntity : class
|
||||
{
|
||||
public readonly Func<TDbContext, DbSet<TEntity>> Create;
|
||||
|
||||
public DbSetFactory(Func<TDbContext, DbSet<TEntity>> create)
|
||||
{
|
||||
Create = create;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user