DDD.Helper
1.0.4.5
dotnet add package DDD.Helper --version 1.0.4.5
NuGet\Install-Package DDD.Helper -Version 1.0.4.5
<PackageReference Include="DDD.Helper" Version="1.0.4.5" />
paket add DDD.Helper --version 1.0.4.5
#r "nuget: DDD.Helper, 1.0.4.5"
// Install DDD.Helper as a Cake Addin
#addin nuget:?package=DDD.Helper&version=1.0.4.5
// Install DDD.Helper as a Cake Tool
#tool nuget:?package=DDD.Helper&version=1.0.4.5
DDD.Helper
It is necessary to add the injection using service.DDDHelperIoC(configuration) from using DDD.Helper.Application.IoC
Add this for UnitOfWork
services.AddDDDHelper(configuration, ServiceLifetime.Scoped);
Add this for Mapper from Mapster
services.AddMappterConfiguration(options => TypeAdapterConfig.GlobalSettings.Default.IgnoreNullValues(true));
Aplication Tier
Use Automapper:
Constructor
public ExampleEntityAppService(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
Method
// Inside method ...
var entity = _mapper.Map<Entity>(dto) //add
// or
var entity = _mapper.Map(dto, entity) //update
...
Use Response Services to Controller
Global return JsonResult from Controller
{
"valid": false,
"message": "any message",
"detail": null,
"data": 0,
"warning": false
}
API Tier - Controller
public async Task<IActionResult> ExampleMethodController() =>
new OkObjectResult(await _anyAppService.ExampleString());
Application Tier - AppService Layer
public Task<JsonResult<string>> ExampleString()
{
return new JsonResult<string>("HelloWord")
}
public Task<JsonResult<EntityDto>> ExampleEntityDto()
{
var value = new EntityDto(); // Do anything
return new JsonResult<EntityDto>(value)
}
public Task<JsonResult<EntityDto>> ExampleEntityDtoWithValidations()
{
var value = new EntityDto(); // Do anything
var validations = _anyService.ValidateEntityAsync(value, new EntityDtoValidator(_serviceProvider))
return new JsonResult<EntityDto>(validations, value)
}
Exception response in Middleware
To catch the exception and send the message response via JsonResult to the Client, use the HandleGlobalExceptionAsync (httpContext, exception) method.
using DDD.Helper.Application.HandlerMiddleware.Response
public async Task InvokeAsync(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception ex)
{
await HandleGlobalExceptionAsync(context, ex);
}
}
Domain Tier
Entity
Set default PrimaryKey to Entity
default key name is [Id] use [:Entity<YourIdType>] Note: If your key is difirent then use EntityConfig in Infraestrucure Tier
public class EntityExample: Entity<int>
{
}
Set Status to Entity
default name status is [Status] required enumerable type
public class EntityExample: Entity<int, ExampleStatus>
{
}
public enum ExampleStatus
{
Active = 0,
Inactive = 1,
}
Entry - COREBIT
Return default Entry from procedure Oracle
Enumerable [StatusResult]
public enum StatusResult
{
Error = 0,
Success = 1,
Warning = 2
}
Entity [EntryResult]
public StatusResult Estado { get; set; }
public string Mensaje { get; set; }
Output default [CUR_Listar]
public class EntryExample
{
...
//any other default params
private object Something { get; } // <== return CURSOR
private int SomethingInt { get; } // <== return number
private string SomethingString { get; } // <== return VARCHAR2
... Others
}
Service
use default methods process
CRUD
Task<TEntity> GetAsync(TId id, include = null);
IQueryable<TEntity> All(bool @readonly = true);
IQueryable<TEntity> Find(predicate, include = null, bool @readonly = true);
Task<int> CountAsync(predicate);
Task<ValidationResult> AddAsync(TEntity entity, params IValidator<TEntity>[] validaciones);
Task<ValidationResult> AddAsync(TEntity entity, IValidator<TEntity> validation);
Task<ValidationResult> UpdateAsync(TEntity entity, params IValidator<TEntity>[] validaciones);
Task<ValidationResult> UpdateAsync(TEntity entity, IValidator<TEntity> validation);
Task<ValidationResult> DeleteAsync(TEntity entity, params IValidator<TEntity>[] validaciones);
Task<ValidationResult> DeleteAsync(TEntity entity, IValidator<TEntity> validation);
Task<ValidationResult> AddRangeAsync(IEnumerable<TEntity> entities, params IValidator<TEntity>[] validaciones);
Task<ValidationResult> AddRangeAsync(IEnumerable<TEntity> entities, IValidator<TEntity> validation);
Validated
Task<ValidationResult> ValidateEntityAsync<TNewEntity>(TNewEntity entity, IValidator<TNewEntity> validation);
Task<ValidationResult> ValidateEntityAsync<TNewEntity>(TNewEntity entity, IEnumerable<IValidator<TNewEntity>> validations);
ValidationResult ConvertToValidationResult(bool[] isValid, string[] message);
use service example
Domain Tier - implement [Interface Service]
public interface IEntityExampleService : IService<ExampleEntity,int[AnyOtherType]>
{
// any customers methods
}
Domain Tier - implement [Class Service]
public class EntityExampleService : Service<ExampleEntity,int[AnyOtherType]>, IEntityExampleService
{
// any customers methods
}
Application Tier - use [Class AppService]
public ExampleEntityAppService(IExampleEntityService exampleEntityService)
{
_exampleEntityService = exampleEntityService;
}
...
// in implemented methods
_exampleEntityService.Find(.......
_exampleEntityService.AddAsync(.......
_exampleEntityService.UpdateAsync(.......
_exampleEntityService.others....
...
Validations
Implement Entity Validations class Note: Review documentation:
public class ExampleEntityValidator : BaseValidator<ExampleEntity>
{
public ExampleEntityValidator(IServiceProvider serviceProvider)
: base(serviceProvider)
{
RuleFor(p => p)
...
}
}
// methods for validations
Use Entity Validations class Note: in Application tier, class AppService
// inside methods
_exampleEntityService.AddAsync(entity, new ExampleEntityValidator(serviceProvider));
_exampleEntityService.anyothers...(entity, new ExampleEntityValidator(serviceProvider));
Infraestructure Tier
HttpClient Config
services.AddHttpClient<IExampleHttpClient, ExampleHttpClient>(c => c.BaseAddress = _httpExampleKey.BaseAddress);
HttpClient Services
using System.Net.Http;
using System.Text.Json;
public class ExampleHttpClient : IExampleHttpClient
{
private readonly HttpClient _httpClient;
private readonly JsonSerializerOptions _jsonOptions;
public ExampleHttpClient(HttpClient httpClient)
{
_httpClient = httpClient;
_jsonOptions = new(JsonSerializerDefaults.Web);
}
public Task<ExampleResponse> Find(ExampleRequest req)
{
return _httpClient.GetAsync<ExampleResponse>(
url: $"/findValues?value={req.value}",
serializerOptions: _jsonOptions);
}
public Task<ExampleResponse> Find(ExampleRequest req)
{
return _httpClient.GetAsync<ExampleResponse>(
url: $"/findValues",
data: req,
serializerOptions: _jsonOptions);
}
public Task<ExampleResponse> Post(ExampleRequest req)
{
return _httpClient.PostAsync<ExampleResponse, ExampleRequest>(
url: $"/postValue",
data: req,
serializerOptions: _jsonOptions);
}
public Task<ExampleResponse> Update(ExampleRequest req)
{
return _httpClient.PutAsync<ExampleResponse, ExampleRequest>(
url: $"/putValue",
data: req,
serializerOptions: _jsonOptions);
}
public Task<ExampleResponse> Delete(ExampleRequest req)
{
return _httpClient.DeleteAsync<ExampleResponse>(
url: $"/deleteValue",
data: req,
serializerOptions: _jsonOptions);
}
}
Mapping TypeGeneric
// TODO: Hacer la descripcion
UpdateAsync with conditions
// TODO: Hacer la descripcion
https://medium.com/@er.bharat1992/writing-readme-md-markdown-file-file-bd711d1afbfa
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
- Dapper (>= 2.0.123)
- FluentValidation (>= 11.2.1)
- Mapster.DependencyInjection (>= 1.0.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Localization.Abstractions (>= 6.0.8)
- Oracle.EntityFrameworkCore (>= 6.21.61)
- Serilog (>= 2.11.0)
- System.Configuration.ConfigurationManager (>= 6.0.0)
- System.IdentityModel.Tokens.Jwt (>= 6.23.1)
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 |
---|---|---|
1.0.4.5 | 435 | 9/9/2022 |
1.0.4.2 | 398 | 9/7/2022 |
1.0.4.1 | 424 | 5/27/2022 |
1.0.4 | 401 | 5/27/2022 |
1.0.3.1 | 516 | 5/16/2022 |
1.0.3 | 531 | 3/29/2022 |
1.0.2.2 | 401 | 10/25/2021 |
1.0.2.1 | 741 | 3/8/2021 |
1.0.1.7 | 527 | 3/3/2021 |
1.0.1.6 | 381 | 3/1/2021 |
1.0.1.5 | 392 | 12/22/2020 |
1.0.1 | 392 | 11/23/2020 |
1.0.0.9 | 431 | 11/21/2020 |
1.0.0.1 | 404 | 11/19/2020 |