Skip to content

Commit

Permalink
updating packages
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarmesquita committed Dec 20, 2023
1 parent d6c82c4 commit e746c08
Show file tree
Hide file tree
Showing 12 changed files with 1,891 additions and 1,198 deletions.
629 changes: 626 additions & 3 deletions src/Repository/AsyncQueryableRepository.cs

Large diffs are not rendered by default.

265 changes: 0 additions & 265 deletions src/Repository/AsyncRepository.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Repository/DefaultUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace eQuantic.Core.Data.EntityFramework.Repository;

public class DefaultUnitOfWork : UnitOfWork<ISqlUnitOfWork, DbContext>, IDefaultUnitOfWork
public class DefaultUnitOfWork : UnitOfWork<DbContext>
{
public DefaultUnitOfWork(IServiceProvider serviceProvider, DbContext context) : base(serviceProvider, context)
{
Expand Down
30 changes: 14 additions & 16 deletions src/Repository/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ namespace eQuantic.Core.Data.EntityFramework.Repository.Extensions;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddQueryableRepositories<TQueryableUnitOfWork>(this IServiceCollection services)
where TQueryableUnitOfWork : class, IDefaultUnitOfWork
where TQueryableUnitOfWork : class, IQueryableUnitOfWork
{
return AddQueryableRepositories<TQueryableUnitOfWork>(services, _ => { });
}

public static IServiceCollection AddQueryableRepositories<TUnitOfWorkInterface, TUnitOfWorkImpl>(
this IServiceCollection services)
where TUnitOfWorkInterface : ISqlUnitOfWork<TUnitOfWorkInterface>
where TUnitOfWorkImpl : class, ISqlUnitOfWork<TUnitOfWorkInterface>
where TUnitOfWorkInterface : IQueryableUnitOfWork
where TUnitOfWorkImpl : class, TUnitOfWorkInterface
{
return AddQueryableRepositories<TUnitOfWorkInterface, TUnitOfWorkImpl>(services, _ => {});
}

public static IServiceCollection AddQueryableRepositories<TUnitOfWorkInterface, TUnitOfWorkImpl>(this IServiceCollection services,
Action<RepositoryOptions> options)
where TUnitOfWorkInterface : ISqlUnitOfWork<TUnitOfWorkInterface>
where TUnitOfWorkImpl : class, ISqlUnitOfWork<TUnitOfWorkInterface>
where TUnitOfWorkInterface : IQueryableUnitOfWork
where TUnitOfWorkImpl : class, TUnitOfWorkInterface
{
var repoOptions = GetOptions(options);
var lifetime = repoOptions.GetLifetime();
Expand All @@ -40,51 +40,49 @@ public static IServiceCollection AddQueryableRepositories<TUnitOfWorkInterface,

public static IServiceCollection AddQueryableRepositories<TQueryableUnitOfWork>(this IServiceCollection services,
Action<RepositoryOptions> options)
where TQueryableUnitOfWork : class, IDefaultUnitOfWork
where TQueryableUnitOfWork : class, IQueryableUnitOfWork
{
var repoOptions = GetOptions(options);
var lifetime = repoOptions.GetLifetime();

AddUnitOfWork<IDefaultUnitOfWork, TQueryableUnitOfWork>(services, lifetime);
AddUnitOfWork<IQueryableUnitOfWork, TQueryableUnitOfWork>(services, lifetime);
AddGenericRepositories(services, lifetime);

return services;
}

public static IServiceCollection AddCustomRepositories<TQueryableUnitOfWork>(this IServiceCollection services,
Action<RepositoryOptions> options)
where TQueryableUnitOfWork : class, IDefaultUnitOfWork
where TQueryableUnitOfWork : class, IQueryableUnitOfWork
{
var repoOptions = GetOptions(options);
var lifetime = repoOptions.GetLifetime();

AddUnitOfWork<IDefaultUnitOfWork, TQueryableUnitOfWork>(services, lifetime);
AddUnitOfWork<IQueryableUnitOfWork, TQueryableUnitOfWork>(services, lifetime);
AddRepositories(services, repoOptions);

return services;
}

private static void AddUnitOfWork<TUnitOfWorkInterface, TUnitOfWorkImpl>(IServiceCollection services, ServiceLifetime lifetime)
where TUnitOfWorkInterface : ISqlUnitOfWork
where TUnitOfWorkImpl : class, ISqlUnitOfWork
where TUnitOfWorkInterface : IQueryableUnitOfWork
where TUnitOfWorkImpl : class, IQueryableUnitOfWork
{
services.TryAdd(new ServiceDescriptor(typeof(TUnitOfWorkInterface), typeof(TUnitOfWorkImpl), lifetime));
services.TryAdd(new ServiceDescriptor(typeof(ISqlUnitOfWork<TUnitOfWorkInterface>), sp => sp.GetRequiredService<TUnitOfWorkInterface>(), lifetime));
services.TryAdd(new ServiceDescriptor(typeof(IQueryableUnitOfWork<TUnitOfWorkInterface>), sp => sp.GetRequiredService<TUnitOfWorkInterface>(), lifetime));

services.TryAdd(new ServiceDescriptor(typeof(IQueryableUnitOfWork), sp => sp.GetRequiredService<TUnitOfWorkInterface>(), lifetime));

services.TryAdd(new ServiceDescriptor(typeof(ISqlUnitOfWork), sp => sp.GetRequiredService<TUnitOfWorkInterface>(), lifetime));
services.TryAdd(new ServiceDescriptor(typeof(IQueryableUnitOfWork), sp => sp.GetRequiredService<TUnitOfWorkInterface>(), lifetime));
}

private static void AddGenericRepositories(IServiceCollection services, ServiceLifetime lifetime)
{
services.TryAdd(new ServiceDescriptor(typeof(Repository<,,>), typeof(Repository<,,>), lifetime));
services.TryAdd(new ServiceDescriptor(typeof(AsyncRepository<,,>), typeof(AsyncRepository<,,>), lifetime));
services.TryAdd(new ServiceDescriptor(typeof(QueryableRepository<,,>), typeof(QueryableRepository<,,>),
lifetime));
services.TryAdd(new ServiceDescriptor(typeof(AsyncQueryableRepository<,,>),
typeof(AsyncQueryableRepository<,,>), lifetime));
}

private static void AddRepositories(IServiceCollection services, RepositoryOptions repoOptions)
{
var types = repoOptions.GetAssemblies()
Expand Down
Loading

0 comments on commit e746c08

Please sign in to comment.