How entities could be connected with each other inside the domain? -


let's assume there 2 domain entities:

  • userimages methods addnewimage(), removeimage($imageid), getimages($from, $count).
  • userprofile fields name, age, mainimageid, etc.

following functionality desired inside domain: when application layer calls userimages -> addnewimage(), userprofile -> mainimageid set automatically in case empty.

so, best way , best place implement in-domain over-entity business logic? domain events observing services, referencing special services entities, or else?

i create entities using kind of factory, i.e.

$userimages = domain::userimages($userid); // getting instance of userimages $newimageid = $userimages -> addnewimage();   // adding new image 

i should mention have lot of logic described above in project.

thank help!

first off, specified in other question, userimages not entity. instead, there entity called userimage refers user's image, singular. userimagerepository can provide access images associated user, using pagination necessary.

now, use case is:

when new user image added, if user's profile image not set, set added image.

the term when indicates domain event. in case, event userimageadded. bold if , subsequent set represent desired behavior in response event.

to implement use case, event must published when user image added , handler implementing desired behavior must subscribed event. linked domain events article provides sample implementation in c#, concept can ported php. overall, required components are:

  • an application service handles adding of user images. service publish event.
  • a domain event publisher called application service , allows decoupling of publishers subscribers.
  • a domain event handler handles userimageadded event , invokes desired behavior.

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -