refactor(DbRepositoryFactory): remvoed

This commit is contained in:
tekh 2025-10-22 17:26:31 +02:00
parent 3b825d4ea3
commit 1febae72c2
4 changed files with 6 additions and 53 deletions

View File

@ -1,18 +0,0 @@
namespace DigitalData.Core.Abstraction.Application.Repository
#if NET
;
#elif NETFRAMEWORK
{
#endif
public interface IRepositoryFactory
{
#if NET
public
#endif
IRepository<TEntity> Get<TEntity>();
}
#if NETFRAMEWORK
}
#endif

View File

@ -4,6 +4,8 @@ using DigitalData.Core.Abstractions.Interfaces;
using DigitalData.Core.Infrastructure.Factory; using DigitalData.Core.Infrastructure.Factory;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions; using System.Linq.Expressions;
using Microsoft.Extensions.DependencyInjection;
#if NETFRAMEWORK #if NETFRAMEWORK
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
@ -130,14 +132,14 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
public class DbRepository : IRepository public class DbRepository : IRepository
{ {
private readonly IRepositoryFactory _factory; private readonly IServiceProvider _provider;
public DbRepository(IRepositoryFactory factory) public DbRepository(IServiceProvider provider)
{ {
_factory = factory; _provider = provider;
} }
public IRepository<TEntity> Entity<TEntity>() where TEntity : IEntity => _factory.Get<TEntity>(); public IRepository<TEntity> Entity<TEntity>() where TEntity : IEntity => _provider.GetRequiredService<IRepository<TEntity>>();
} }
#if NETFRAMEWORK #if NETFRAMEWORK

View File

@ -29,9 +29,6 @@ public static class DependencyInjection
// register db repository // register db repository
services.AddSingleton<IRepository, DbRepository>(); services.AddSingleton<IRepository, DbRepository>();
// register db repository factory
services.AddSingleton<IRepositoryFactory, DbRepositoryFactory>();
return services; return services;
} }

View File

@ -1,28 +0,0 @@
using DigitalData.Core.Abstraction.Application.Repository;
using Microsoft.Extensions.DependencyInjection;
#if NETFRAMEWORK
using System;
#endif
namespace DigitalData.Core.Infrastructure.Factory
#if NET
;
#elif NETFRAMEWORK
{
#endif
public class DbRepositoryFactory : IRepositoryFactory
{
private readonly IServiceProvider _provider;
public DbRepositoryFactory(IServiceProvider provider)
{
_provider = provider;
}
public IRepository<TEntity> Get<TEntity>() => _provider.GetRequiredService<IRepository<TEntity>>();
}
#if NETFRAMEWORK
}
#endif