From 90ce4e487ce2507674012a5ee411f63a0ebe1dbc Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 22 Oct 2025 17:34:28 +0200 Subject: [PATCH] refactor: remove IRepository and DbRepository --- .../Factory.cs | 53 ------------- .../Repository/Extensions.cs | 79 ------------------- .../Repository/IRepository.cs | 6 -- .../DbRepository.cs | 13 --- .../DependencyInjection.cs | 3 - 5 files changed, 154 deletions(-) delete mode 100644 DigitalData.Core.Abstraction.Application/Factory.cs delete mode 100644 DigitalData.Core.Abstraction.Application/Repository/Extensions.cs diff --git a/DigitalData.Core.Abstraction.Application/Factory.cs b/DigitalData.Core.Abstraction.Application/Factory.cs deleted file mode 100644 index fbe3ed9..0000000 --- a/DigitalData.Core.Abstraction.Application/Factory.cs +++ /dev/null @@ -1,53 +0,0 @@ -#if NETFRAMEWORK -using System; -#endif - -using DigitalData.Core.Abstraction.Application.Repository; -using Microsoft.Extensions.DependencyInjection; - -namespace DigitalData.Core.Abstraction.Application -#if NET - ; -#elif NETFRAMEWORK -{ -#endif - -public interface IFactory : IServiceCollection, IServiceProvider -{ -#if NET - public -#endif - IRepository Repository { get; } -} - -public class Factory : ServiceCollection, IFactory, IServiceCollection, IServiceProvider -{ - private readonly Lazy _rootProvider; - - private Factory() - { - _rootProvider = new Lazy(this.BuildServiceProvider); - } - - public object -#if NET - ? -#endif - GetService(Type serviceType) - { - return _rootProvider.Value.GetService(serviceType); - } - - public IRepository Repository => _rootProvider.Value.GetRequiredService(); - - public static readonly IFactory Shared = new Factory(); -} - -public static class Factory -{ - public static IRepository Repository() => Factory.Shared.GetRequiredService>(); -} - -#if NETFRAMEWORK - } -#endif \ No newline at end of file diff --git a/DigitalData.Core.Abstraction.Application/Repository/Extensions.cs b/DigitalData.Core.Abstraction.Application/Repository/Extensions.cs deleted file mode 100644 index 32a3d87..0000000 --- a/DigitalData.Core.Abstraction.Application/Repository/Extensions.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System.Linq.Expressions; -using DigitalData.Core.Abstractions.Interfaces; -#if NETFRAMEWORK -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using System.Linq; -#endif - -namespace DigitalData.Core.Abstraction.Application.Repository -#if NET - ; -#elif NETFRAMEWORK - { -#endif - -public static class Extensions -{ - #region IRepository - #region Read - public static IEnumerable GetAll(this IRepository repository) where TEntity : IEntity - => repository.Entity().GetAll(); - - public static Task> GetAllAsync(this IRepository repository, CancellationToken cancel = default) where TEntity : IEntity - => repository.Entity().GetAllAsync(cancel); - - public static IQueryable Where(this IRepository repository, Expression> expression) - where TEntity : IEntity - => repository.Entity().Where(expression); - #endregion - - #region Create - public static Task CreateAsync(this IRepository repository, TEntity entity, CancellationToken cancel = default) - where TEntity : IEntity - => repository.Entity().CreateAsync(entity, cancel); - - public static Task CreateAsync(this IRepository repository, TDto dto, CancellationToken cancel = default) - where TEntity : IEntity - where TDto : IDto - => repository.Entity().CreateAsync(dto, cancel); - - public static Task> CreateAsync(this IRepository repository, IEnumerable entities, CancellationToken cancel = default) - where TEntity : IEntity - => repository.Entity().CreateAsync(entities, cancel); - - public static Task> CreateAsync(this IRepository repository, IEnumerable dtos, CancellationToken cancel = default) - where TEntity : IEntity - where TDto : IDto - => repository.Entity().CreateAsync(dtos, cancel); - #endregion Create - - #region Update - public static Task UpdateAsync(this IRepository repository, TDto dto, Expression> expression, CancellationToken cancel = default) - where TEntity : IEntity - where TDto : IDto - => repository.Entity().UpdateAsync(dto, expression, cancel); - - public static Task UpdateAsync(this IRepository repository, TDto dto, Func, IQueryable> query, CancellationToken cancel = default) - where TEntity : IEntity - where TDto : IDto - => repository.Entity().UpdateAsync(dto, query, cancel); - #endregion - - #region Delete - public static Task DeleteAsync(this IRepository repository, Expression> expression, CancellationToken cancel = default) - where TEntity : IEntity - => repository.Entity().DeleteAsync(expression, cancel); - - public static Task DeleteAsync(this IRepository repository, Func, IQueryable> query, CancellationToken cancel = default) - where TEntity : IEntity - => repository.Entity().DeleteAsync(query, cancel); - #endregion - #endregion -} - -#if NETFRAMEWORK - } -#endif \ No newline at end of file diff --git a/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs b/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs index 070145e..27dd627 100644 --- a/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs +++ b/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs @@ -99,12 +99,6 @@ public interface IRepository IQueryable ReadOnly(); #endregion } - -public interface IRepository -{ - IRepository Entity() where TEntity : IEntity; -} - #if NETFRAMEWORK } #endif \ No newline at end of file diff --git a/DigitalData.Core.Infrastructure/DbRepository.cs b/DigitalData.Core.Infrastructure/DbRepository.cs index 695d6f4..fde9865 100644 --- a/DigitalData.Core.Infrastructure/DbRepository.cs +++ b/DigitalData.Core.Infrastructure/DbRepository.cs @@ -129,19 +129,6 @@ public class DbRepository : IRepository where TDbC public virtual IQueryable ReadOnly() => Entities.AsNoTracking(); #endregion } - -public class DbRepository : IRepository -{ - private readonly IServiceProvider _provider; - - public DbRepository(IServiceProvider provider) - { - _provider = provider; - } - - public IRepository Entity() where TEntity : IEntity => _provider.GetRequiredService>(); -} - #if NETFRAMEWORK } #endif \ No newline at end of file diff --git a/DigitalData.Core.Infrastructure/DependencyInjection.cs b/DigitalData.Core.Infrastructure/DependencyInjection.cs index b79618a..1acd7b9 100644 --- a/DigitalData.Core.Infrastructure/DependencyInjection.cs +++ b/DigitalData.Core.Infrastructure/DependencyInjection.cs @@ -26,9 +26,6 @@ public static class DependencyInjection options.Invoke(cfg); cfg.RegisterAllServices(services); - // register db repository - services.AddSingleton(); - return services; }