开发者

Repository pattern aggregate and aggregate root with Entity Framework 4.0

I have a question on implementing the repository pattern with my data model. I have searched online and looked into a lot of posts but I do not find any answer which clears my doubts. Basically our domain model goes like below we have a client object which has a lot of child objects and some child objects in turn will have a child objects and at any point of time these child objects without their parent objects are not needed and does not make any sense in the application.

client
 --> client zip codes
 --> client phone history
 --> client medical history
 --> client direct services
      --> client direct service assessments
      --> client direct service risk reductions
 --> client housing
      --> client housing landlord

and it goes like this. So from the above representation I have some aggregates and the root is the client object so I was thinking of creating a repository at the aggregate root level which is the client. My question is how do I开发者_如何学JAVA handle the other aggregates. Can anyone please provide me some ideas on this.

Thanks, Ajay.


In general, it is the repository's responsibility to prepare the aggregate root for use by the rest of the program. So you should query the repository for a client, and it should return a full client object complete with zip codes, phone history, medical history, etc. The idea of an aggregate root is that no outside code should have to worry about getting clients without those other aggregates available.

Looking at it another way, since you are creating a client repository and client is the aggregate root, it is the client repository's job to compose all subobjects, even if they are themselves aggregates.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜