开发者

DDD - Returning entity in response to a service operation

开发者 https://www.devze.com 2022-12-12 00:03 出处:网络
I am new to domain driven development & have a simple question. If a service 开发者_如何学Goneeds to generate some entity as a response to an operation then how should it be done? One of the ways

I am new to domain driven development & have a simple question. If a service 开发者_如何学Goneeds to generate some entity as a response to an operation then how should it be done? One of the ways is to inject entity factory in the service instance. Is there any other better solution for the same ?


Factories are usually for complex entity creation. You could simply new up the object. Its not clear whether you mean creating or retrieving. If you are retrieving, you can inject a repository and use that. Also, services typically return DTOs, not the actual entities themselves. Outside of the domain should not know about entities.

0

精彩评论

暂无评论...
验证码 换一张
取 消