Giter VIP home page Giter VIP logo

Comments (2)

yvoyer avatar yvoyer commented on August 16, 2024 1

When using a UUID (recommended), I usually create the new Id in the controller (as your example 2). That way you can fetch it after the handler is executed.

When not using a UUID but an auto increment (not recommended), you can can use a listener on the specific domain event, or ask the repository to generate an Id (based on autoincrement) $this->repository->generateTaskId (). The AI solution also comes with possible problems when 2 records are added simultaneously.

On a side note, you should wrap the call to the handle with transaction, commit, rollback, since if an error occurred during the creation, the repo would not have the entity, and the view might be broken.

from php-ddd.

webdevilopers avatar webdevilopers commented on August 16, 2024 1

Welcome to PHPDDD @borNfreee !

@yvoyer has some good advice there! Start creating your own IDs (UUID recommended) - "TELL, don't ask"! This decouples your application from the persistence layer.

from php-ddd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.