Reputation: 484
This question it's about ABP framework implementation of DDD,in the Domain layer there a class named "Entity"Manager, this class is a factory for the domain entity and have the method CreateAsync for entity instantiation. I want to reuse this method (or a better approach) to update my entity without redoing the same logic on Application layer. This is the method on AporteManager.
public async Task<Aporte> CreateAsync(
AporteValidation valid
)
{
var icontaBancaria = await _contaBancariaRepository.WithDetailsAsync(
x => x.Banco, x => x.FonteDeRecurso, x => x.CodigoDeAplicacao, x => x.Fundo, x => x.FonteDeRecursoSICONFI);
var contaBancaria = icontaBancaria.Where(x => x.Id == valid.ContaBancariaId).FirstOrDefault();
valid.FonteDeRecursoId = contaBancaria.FonteDeRecurso?.Id;
valid.CodigoDeAplicacaoId = contaBancaria.CodigoDeAplicacao?.Id;
return new Aporte(
valid
);
}
And this is my update method on Application:
[Authorize(ContabilidadePermissions.Aporte.Edit)]
public async Task UpdateAsync(int id, CreateUpdateAporteDto input)
{
try
{
var aporte = await _aporteRepository.GetAsync(id);
if (aporte is not null)
{
var validation = ObjectMapper.Map<CreateUpdateAporteDto, AporteValidation>(input);
var aporteValidado = await _aporteManager.CreateAsync(validation);
aporte = ObjectMapper.Map(aporteValidado, aporte);
await _aporteRepository.UpdateAsync(aporte);
//aporte = ObjectMapper.Map(input, aporte);
//await _aporteRepository.UpdateAsync(aporte);
}
else
{
throw new EntidadeNaoExisteParaSerAtualizadaException();
}
}
catch (Exception ex)
{
throw new RegistroJaExisteGenericoException("Aporte", "Código");
}
}
Although UpdateAsync is not working, I'm not just looking to a solution, but a correct, maintainable and simple DDD solution. Here is a sample of the project: https://github.com/heitorgiacominibrasil/DomainManager
Upvotes: 0
Views: 473
Reputation: 46
you must see the tutorials in the docs.abp.io
https://docs.abp.io/en/abp/latest/Tutorials/Part-6?UI=MVC&DB=Mongo
AuthorManager: The Domain Service
https://docs.abp.io/en/abp/latest/Tutorials/Part-6?UI=MVC&DB=Mongo#authormanager-the-domain-service
Upvotes: 1