I work for a store and I am creating a Restful web api using the EF code-first for my Data layer. I have one class library: StoreName.Domain.Inventory
and another: StoreName.Domain.Membership
Currently I have written a DbContext for each library and an object repository for each.
My question is "If I want all my tables to be created in the same database, doesn't both my class libraries have to share the same DbContext class?"
If this is true what is the best way to structure? Should I create a third class libarary that references both the first two libraries, for the DbContext class, and then move the repositories to that library?
This is the first time I am trying to really focus on the structure for maintainabiliy purposes, any suggestions would be greatly appreciated!
Doers get what they want! Everyone else gets what they get.
How about defining all of your entites in one library and then you can split your repositories into separate libraries that can each reference the entity library.
Or you can have all of the entities in one library and all of the repositories in a second library. This way would keep all classes with similar functionality in the same location.
Marked as answer by remojr76 on Nov 11, 2012 01:43 PM
Or you can have all of the entities in one library and all of the repositories in a second library. This way would keep all classes with similar functionality in the same location.
This really made me think about the correct approach, I am just trying to really keep each concern separate just for future maintenance and extensibility. So I realize that the answer to my question depends of the exact interaction of my business objects.
In this particular case you second approach will work perfect. Thanks for the reponse!
Doers get what they want! Everyone else gets what they get.
remojr76
Participant
902 Points
303 Posts
Scenerio Question about EF
Nov 09, 2012 07:20 PM|LINK
I work for a store and I am creating a Restful web api using the EF code-first for my Data layer. I have one class library: StoreName.Domain.Inventory
and another: StoreName.Domain.Membership
Currently I have written a DbContext for each library and an object repository for each.
My question is "If I want all my tables to be created in the same database, doesn't both my class libraries have to share the same DbContext class?"
If this is true what is the best way to structure? Should I create a third class libarary that references both the first two libraries, for the DbContext class, and then move the repositories to that library?
This is the first time I am trying to really focus on the structure for maintainabiliy purposes, any suggestions would be greatly appreciated!
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Scenerio Question about EF
Nov 10, 2012 11:46 PM|LINK
Hello,
What does this mean? Can you offer us your detailled codes?
Nakor
Member
336 Points
60 Posts
Re: Scenerio Question about EF
Nov 11, 2012 01:06 PM|LINK
How about defining all of your entites in one library and then you can split your repositories into separate libraries that can each reference the entity library.
Or you can have all of the entities in one library and all of the repositories in a second library. This way would keep all classes with similar functionality in the same location.
remojr76
Participant
902 Points
303 Posts
Re: Scenerio Question about EF
Nov 11, 2012 01:43 PM|LINK
This really made me think about the correct approach, I am just trying to really keep each concern separate just for future maintenance and extensibility. So I realize that the answer to my question depends of the exact interaction of my business objects. In this particular case you second approach will work perfect. Thanks for the reponse!