正确的方法在插入和更新实体上使用domainmanager类(聚集根)
这个问题是关于DDD的ABP框架实现的,在域层中,该类名为“ Entity”管理器,此类是域实体的工厂,并且具有实体实例化的方法createSync。我想重复使用此方法(或更好的方法)来更新我的实体,而无需在应用程序层上重复相同的逻辑。这是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
);
}
这是我在应用程序上的更新方法:
[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");
}
}
尽管UpdateAsync不起作用,但我不仅要寻求解决方案,而且是一种正确,可维护和简单的DDD解决方案。这是该项目的一个示例: httpps://github.com/github.com/heitorgiacominibrasil/domainmanager
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看到教程
您必须在docs.abp.io中 nofollow noreferrer“> https://docs.abp.io/en/abp/latest/tutorials/part-6?ui=mvc&; db=mongo
fearmanager:domain Service
https://docs.abp.io/en/abp/latest/tutorials/part-6?ui=mvc&db=mongo#authormanager-the-domain-nomain-service
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