Last post Sep 20, 2012 01:20 AM by arefkarimi
Sep 20, 2012 01:20 AM|arefkarimi|LINK
I am trying to designed a sort of architecture that employs Entity Framework and Repository pattern.
The way it works is:
0- This has four components: a- Core which has interfaces and entity definitions. 2- Data which does CRUD. 3- Service which includes business classes. 4- Website
The way it's meant to work is:
1- We add an .EDMX file to CORE component.
2- We change the accessibility of the ObjectContext (diagram) to Internal so that it becomes inaccessible from other components.
3- We create an instance of a UnitOfWork class (implements IUnitOfWork) which wraps an instance of an ObjectContext object.
4- We create instances of EFRepository class that implements IRepository interface.
5- We work with unit of work and repositories to perform CRUD.
This way we can put the defenition of entities along with the interfaces in Core component. Then we can put the implementation of UnitOfWork along with ObjectContext that actually does the CRUD in another component say DATA (which is missing in this diagram).
The issue is that we want to use dependency injection in order to inject UnitOfWork and Business classes. We have to do it in our web site (through Global.asax file) so the web site has to have acess to the interface defenitions. Thus it references CORE.
But then it has to have a reference to DATA component that contains the actual implementation of UnitOfWork. This way the web site (presentaiton layer) will have a direct reference to data layer which is not very good !
Instead of web site having access to core and data componets I put the interfaces and their implementations in core and removed the data. I ended up having a design like this:
I am not happy with this to be honest because I'd like to have a seperate DATA component that is not referenced by Website.
This is the code that configures the dependency injection container:
Would be great if you could help me have the data component.
p.s. Using self tracking entities and code first approach is not an option due to business constraints!