DrMadWill.Layers
5.0.0
dotnet add package DrMadWill.Layers --version 5.0.0
NuGet\Install-Package DrMadWill.Layers -Version 5.0.0
<PackageReference Include="DrMadWill.Layers" Version="5.0.0" />
paket add DrMadWill.Layers --version 5.0.0
#r "nuget: DrMadWill.Layers, 5.0.0"
// Install DrMadWill.Layers as a Cake Addin #addin nuget:?package=DrMadWill.Layers&version=5.0.0 // Install DrMadWill.Layers as a Cake Tool #tool nuget:?package=DrMadWill.Layers&version=5.0.0
Layers
Description
Layers is a software project developed primarily in C#.
Installation
To install Layers, you will need .
You can clone the repository using the following command:
- bash
- Copy code
git clone https://github.com/DrMadWill/Layers.git
- Copy code
- bash
You can install the package form your project using the following command:
- nuget
- terminal>
dotnet add package DrMadWill.Layers --version 3.1.0
- nuget-terminal>
NuGet\Install-Package DrMadWill.Layers -Version 3.1.0
- terminal>
- nuget
Usage
Here is how you can use Layers: This class must be added your project.
public static class ServiceRegistration
{
public static void AddLayerServices(this IServiceCollection services)
{
if (services == null) throw new AggregateException("service is null");
#region Repositories
services.AddScoped(typeof(IReadRepository<,>), typeof(ReadRepository<,>));
services.AddScoped(typeof(IWriteRepository<,>), typeof(WriteRepository<,>));
services.AddScoped<IQueryRepositories, DQueryRepositories>();
services.AddScoped<IUnitOfWork, DUnitOfWork>();
#endregion
#region Services
services.AddScoped<IServiceManager, DServiceManager>();
#endregion
}
}
- DQueryRepositories
public class DQueryRepositories : QueryRepositories, IQueryRepositories
{
public DQueryRepositories(DictContext dictContext, IMapper mapper) : base(dictContext, mapper, typeof(ServiceRegistration))
{
}
}
- DUnitOfWork
public class DUnitOfWork:UnitOfWork
{
public DUnitOfWork(DictContext dictContext) : base(dictContext,typeof(ServiceRegistration))
{
}
}
- DServiceManager
public class DServiceManager :ServiceManager
{
public DServiceManager(IUnitOfWork unitOfWork, IQueryRepositories queryRepositories, IMapper mapper,ILoggerFactory loggerFactory) :
base(unitOfWork, queryRepositories, mapper,loggerFactory,typeof(ServiceRegistration))
{
}
}
For example : Dictionary Type Service Add
public class DictionaryTypeService:BaseService,IDictionaryTypeService
{
private readonly IReadRepository<DictionaryType, int> _read;
private readonly IWriteRepository<DictionaryType, int> _write;
public DictionaryTypeService(IUnitOfWork unitOfWork, IQueryRepositories queryRepositories,IMapper mapper,ILogger<DictionaryTypeService> logger) :
base(unitOfWork, queryRepositories,mapper,logger)
{
_read = QueryRepositories.Repository<DictionaryType,int>();
_write = UnitOfWork.Repository<DictionaryType,int>();
}
public async Task<SourcePaged<DictionaryTypeDto>> GetAll(DictionaryTypeFilter filter,PageReq page)
{
IQueryable<DictionaryType> query = QueryRepositories.Repository<DictionaryType, int>().GetAllQueryable()
.OrderByDescending(s => s.Hierarchy);
if (filter != null)
query = filter.Filtered(query);
var source =
await SourcePaged<DictionaryTypeDto>.PagedAsync(query, page);
return Mapper.Map<SourcePaged<DictionaryTypeDto>>(source);
}
public async Task<DictionaryTypeDto> Get(int id)
{
var dictionaryType = await _read.GetFirstAsync(s => s.Id == id);
if (dictionaryType == null) return null;
var result = Mapper.Map<DictionaryTypeDto>(dictionaryType);
return result;
}
public Task<bool> AddAsync(AddDictionaryTypeReq req)
=> CompleteProcess(async () =>
{
var dictionaryType = Mapper.Map<DictionaryType>(req);
await _write.AddAsync(dictionaryType);
await UnitOfWork.CommitAsync();
});
public Task<bool> UpdateAsync(UpdateDictionaryTypeReq req)
=> CompleteProcess(async () =>
{
var dictionaryType = await _read.GetAllQueryable(true).FirstOrDefaultAsync(s => s.Id == req.Id);
if (dictionaryType == null) throw new Exception("Dictionary Type is not found");
Mapper.Map(req, dictionaryType);
await _write.UpdateAsync(dictionaryType);
await UnitOfWork.CommitAsync();
});
public Task<bool> DeleteAsync(int id)
=> CompleteProcess(async () =>
{
var dictionaryType =await _read.GetAllQueryable(true).FirstOrDefaultAsync(s => s.Id == id);
if (dictionaryType == null) throw new Exception("Dictionary Type is not found");
await _write.DeleteAsync(dictionaryType);
await UnitOfWork.CommitAsync();
});
}
Contributing
Contributions to Layers are welcome! Please feel free to fork the repository, make changes, and submit pull requests.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Acknowledgments
- me
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- AutoMapper (>= 12.0.1)
- Microsoft.EntityFrameworkCore (>= 6.0.23)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.0 | 143 | 2/22/2024 |
4.2.0 | 130 | 2/22/2024 |
4.1.0 | 90 | 2/22/2024 |
4.0.0 | 107 | 2/22/2024 |
3.1.2 | 129 | 2/9/2024 |
3.1.1 | 131 | 1/28/2024 |
3.1.0 | 106 | 1/26/2024 |
3.0.0 | 104 | 1/25/2024 |
2.4.1 | 105 | 1/25/2024 |
2.3.1 | 108 | 1/25/2024 |
2.3.0 | 106 | 1/24/2024 |
2.2.1 | 107 | 1/24/2024 |
2.1.1 | 85 | 1/24/2024 |
2.0.1 | 114 | 1/23/2024 |
2.0.0 | 107 | 1/23/2024 |
1.9.0 | 112 | 1/19/2024 |
1.8.0 | 126 | 1/11/2024 |
1.7.1 | 162 | 12/23/2023 |
1.7.0 | 117 | 12/23/2023 |
1.6.0 | 128 | 12/22/2023 |
1.5.0 | 126 | 12/20/2023 |
1.4.2 | 136 | 12/20/2023 |
1.3.2 | 132 | 12/19/2023 |
1.2.2 | 131 | 12/19/2023 |
1.2.1 | 121 | 12/19/2023 |
1.2.0 | 120 | 12/19/2023 |
1.1.2 | 129 | 12/19/2023 |
1.0.2 | 135 | 12/19/2023 |
1.0.1 | 122 | 12/19/2023 |
1.0.0 | 134 | 12/19/2023 |