Doubt Model Service DDD

Asked

Viewed 185 times

2

I have a question about a project that follows the DDD architecture model.

In a service model I need information that is the result of a method from another service, which is the correct way for me to get this information, i create a property of that service and place it in the constructor to do the dependency injection or I must get this information in the previous layer, the same one I call this first service and pass this value as parameter?

My doubt if from the pq I created the second service property and did the dependency injection but then gave error pq says that there are references of cyclic dependency injection and need to remove the property of that second service and dependency injection.

  • 5

    Do you have code? I could ask the question so we can help you better?

1 answer

0

It’s hard to answer without knowing the context, but I’ll try.

If the two services depend on each other, I advise you to create a third service that injects the first two and bridge between them.

Example:

Service_alpha -> Method_one(Service_beta)

Service_beta -> Method 2(Service_alpha)

Service_delta -> Get Alpha and Beta by DI.

Service_delta -> Method_three() -> Executes the operation in Alpha passing Beta as parameter.

Service_delta -> Method_four() -> Executes the operation in Beta, passing Alpha as parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.