refactor(DbRepositoryFactory): remvoed
This commit is contained in:
parent
3b825d4ea3
commit
1febae72c2
@ -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
|
||||
@ -4,6 +4,8 @@ using DigitalData.Core.Abstractions.Interfaces;
|
||||
using DigitalData.Core.Infrastructure.Factory;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
#if NETFRAMEWORK
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
@ -130,14 +132,14 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
||||
|
||||
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
|
||||
|
||||
@ -29,9 +29,6 @@ public static class DependencyInjection
|
||||
// register db repository
|
||||
services.AddSingleton<IRepository, DbRepository>();
|
||||
|
||||
// register db repository factory
|
||||
services.AddSingleton<IRepositoryFactory, DbRepositoryFactory>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user