正确的方法在插入和更新实体上使用domainmanager类(聚集根)

发布于 2025-02-14 02:22:32 字数 2214 浏览 28 评论 0原文

这个问题是关于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘亓 2025-02-21 02:22:32

看到教程

您必须在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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文