Compare commits
4 Commits
3b825d4ea3
...
f2808d090f
| Author | SHA1 | Date | |
|---|---|---|---|
| f2808d090f | |||
| 0084e6f758 | |||
| 90ce4e487c | |||
| 1febae72c2 |
@ -12,9 +12,9 @@
|
|||||||
<PackageIcon>core_icon.png</PackageIcon>
|
<PackageIcon>core_icon.png</PackageIcon>
|
||||||
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
||||||
<PackageTags>digital data core application clean architecture abstraction</PackageTags>
|
<PackageTags>digital data core application clean architecture abstraction</PackageTags>
|
||||||
<Version>1.3.6</Version>
|
<Version>1.3.7</Version>
|
||||||
<AssemblyVersion>1.3.6</AssemblyVersion>
|
<AssemblyVersion>1.3.7</AssemblyVersion>
|
||||||
<FileVersion>1.3.6</FileVersion>
|
<FileVersion>1.3.7</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -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<IServiceProvider> _rootProvider;
|
|
||||||
|
|
||||||
private Factory()
|
|
||||||
{
|
|
||||||
_rootProvider = new Lazy<IServiceProvider>(this.BuildServiceProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
public object
|
|
||||||
#if NET
|
|
||||||
?
|
|
||||||
#endif
|
|
||||||
GetService(Type serviceType)
|
|
||||||
{
|
|
||||||
return _rootProvider.Value.GetService(serviceType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRepository Repository => _rootProvider.Value.GetRequiredService<IRepository>();
|
|
||||||
|
|
||||||
public static readonly IFactory Shared = new Factory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Factory<TEntity>
|
|
||||||
{
|
|
||||||
public static IRepository<TEntity> Repository() => Factory.Shared.GetRequiredService<IRepository<TEntity>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -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<TEntity> GetAll<TEntity>(this IRepository repository) where TEntity : IEntity
|
|
||||||
=> repository.Entity<TEntity>().GetAll();
|
|
||||||
|
|
||||||
public static Task<IEnumerable<TEntity>> GetAllAsync<TEntity>(this IRepository repository, CancellationToken cancel = default) where TEntity : IEntity
|
|
||||||
=> repository.Entity<TEntity>().GetAllAsync(cancel);
|
|
||||||
|
|
||||||
public static IQueryable<TEntity> Where<TEntity>(this IRepository repository, Expression<Func<TEntity, bool>> expression)
|
|
||||||
where TEntity : IEntity
|
|
||||||
=> repository.Entity<TEntity>().Where(expression);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Create
|
|
||||||
public static Task<TEntity> CreateAsync<TEntity>(this IRepository repository, TEntity entity, CancellationToken cancel = default)
|
|
||||||
where TEntity : IEntity
|
|
||||||
=> repository.Entity<TEntity>().CreateAsync(entity, cancel);
|
|
||||||
|
|
||||||
public static Task<TEntity> CreateAsync<TEntity, TDto>(this IRepository repository, TDto dto, CancellationToken cancel = default)
|
|
||||||
where TEntity : IEntity
|
|
||||||
where TDto : IDto<TEntity>
|
|
||||||
=> repository.Entity<TEntity>().CreateAsync(dto, cancel);
|
|
||||||
|
|
||||||
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity>(this IRepository repository, IEnumerable<TEntity> entities, CancellationToken cancel = default)
|
|
||||||
where TEntity : IEntity
|
|
||||||
=> repository.Entity<TEntity>().CreateAsync(entities, cancel);
|
|
||||||
|
|
||||||
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity, TDto>(this IRepository repository, IEnumerable<TDto> dtos, CancellationToken cancel = default)
|
|
||||||
where TEntity : IEntity
|
|
||||||
where TDto : IDto<TEntity>
|
|
||||||
=> repository.Entity<TEntity>().CreateAsync(dtos, cancel);
|
|
||||||
#endregion Create
|
|
||||||
|
|
||||||
#region Update
|
|
||||||
public static Task UpdateAsync<TEntity, TDto>(this IRepository repository, TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default)
|
|
||||||
where TEntity : IEntity
|
|
||||||
where TDto : IDto<TEntity>
|
|
||||||
=> repository.Entity<TEntity>().UpdateAsync(dto, expression, cancel);
|
|
||||||
|
|
||||||
public static Task UpdateAsync<TEntity, TDto>(this IRepository repository, TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
|
|
||||||
where TEntity : IEntity
|
|
||||||
where TDto : IDto<TEntity>
|
|
||||||
=> repository.Entity<TEntity>().UpdateAsync(dto, query, cancel);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Delete
|
|
||||||
public static Task DeleteAsync<TEntity>(this IRepository repository, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default)
|
|
||||||
where TEntity : IEntity
|
|
||||||
=> repository.Entity<TEntity>().DeleteAsync(expression, cancel);
|
|
||||||
|
|
||||||
public static Task DeleteAsync<TEntity>(this IRepository repository, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
|
|
||||||
where TEntity : IEntity
|
|
||||||
=> repository.Entity<TEntity>().DeleteAsync(query, cancel);
|
|
||||||
#endregion
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -99,12 +99,6 @@ public interface IRepository<TEntity>
|
|||||||
IQueryable<TEntity> ReadOnly();
|
IQueryable<TEntity> ReadOnly();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IRepository
|
|
||||||
{
|
|
||||||
IRepository<TEntity> Entity<TEntity>() where TEntity : IEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -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 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;
|
||||||
@ -127,19 +129,6 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
|||||||
public virtual IQueryable<TEntity> ReadOnly() => Entities.AsNoTracking();
|
public virtual IQueryable<TEntity> ReadOnly() => Entities.AsNoTracking();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DbRepository : IRepository
|
|
||||||
{
|
|
||||||
private readonly IRepositoryFactory _factory;
|
|
||||||
|
|
||||||
public DbRepository(IRepositoryFactory factory)
|
|
||||||
{
|
|
||||||
_factory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRepository<TEntity> Entity<TEntity>() where TEntity : IEntity => _factory.Get<TEntity>();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -26,12 +26,6 @@ public static class DependencyInjection
|
|||||||
options.Invoke(cfg);
|
options.Invoke(cfg);
|
||||||
cfg.RegisterAllServices(services);
|
cfg.RegisterAllServices(services);
|
||||||
|
|
||||||
// register db repository
|
|
||||||
services.AddSingleton<IRepository, DbRepository>();
|
|
||||||
|
|
||||||
// register db repository factory
|
|
||||||
services.AddSingleton<IRepositoryFactory, DbRepositoryFactory>();
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,9 +13,9 @@
|
|||||||
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
||||||
<RepositoryType>digital data core abstractions clean architecture</RepositoryType>
|
<RepositoryType>digital data core abstractions clean architecture</RepositoryType>
|
||||||
<PackageTags>digital data core infrastructure clean architecture</PackageTags>
|
<PackageTags>digital data core infrastructure clean architecture</PackageTags>
|
||||||
<Version>2.4.4</Version>
|
<Version>2.4.5</Version>
|
||||||
<AssemblyVersion>2.4.4</AssemblyVersion>
|
<AssemblyVersion>2.4.5</AssemblyVersion>
|
||||||
<FileVersion>2.4.4</FileVersion>
|
<FileVersion>2.4.5</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -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