views:

130

answers:

2

Hello, I beginning a new project and I need to create a Project for implementing Entity Framework 4.0 and Unity Framework 2.0 along with Enterprise Library 5.0.

I am very new to Entity Framework and Unity Framework and getting confused in how I can get normal Object BO's and DAL with Database.

Can someone point me to some simple examples to start on both in a same project. Later I need to use ASP.NET MVC 2.0 for the UI.

I have seen Julie Lerman's Video for Entity Framework I can get the Tables as Entity but after that I have no Idea where will Unity, Enterprise Library will fit in. I am lost after that.

Some one please help me.

+1  A: 

Are you sure you want to use Enterprise Library or Unity Framework? At the moment I have a feeling that you don't know what are these API for.

Anyway. How to use those frameworks together? Some example:

  • You will create Entity model in EF 4.0 and you will define POCO classes
  • You will create interfaces for your Data Access layer
  • You will create Data Access layer which will be based on Repository and Unit of work patterns. This layer will encapsulate working with EF 4.0
  • You will create interfaces for Business layer
  • You will create Business layer which will do your business logic and use Data access layer to get and store data. You will use dependency injection pattern so that DAL classes are injected to your BL classes. Your business layer will work with defined interfaces not with concrete implementation of DAL classes.
  • You can use Validation Application block to handle validation of your POCO entity classes.
  • You can use Exception Handling Application block to handle exception in global way.
  • You can use Logging Application block to handle application logging
  • You can use Unity to inject some general functionality as Aspects. Formerly known as Policy Application Block.
  • You will create your ASP.NET MVC application
  • You will create new Controller Factory which will use Unity to create instance of controller.
  • Each controller will use Dependency injection to get Business layer classes needed for its operation. Your controllers will work with defined interfaces not with concrete implementation of BL classes.
  • You will configure Unity to resolve controllers, business classes and data access layer classes. Resolving will map concrete implementation of BL and DAL classes to used interfaces.

If you want to use mentioned frameworks you should have general idea about mentioned concepts. Almost each of this points is suitable for separate question. Answering all these points is like writing a book ...

Ladislav Mrnka
At the moment the client has asked me to use Entity Framework, Unity Framework and Enterprise Library. Enterprise Library might not be used here. But EF and Unity will be used Definitely.Can you point me towards some working example of the points you said above.
Mohit
Check this article: http://weblogs.asp.net/shijuvarghese/archive/2008/10/24/asp-net-mvc-tip-dependency-injection-with-unity-application-block.aspx
Ladislav Mrnka
A: 

I've learned a lot by looking at the code of some projects listed in this article: http://richarddingwall.name/2008/11/02/best-practice-dddtdd-aspnet-mvc-example-applications/. I recommend you to take a look to the code of CarTrackr, I think it ressemble to what you want to do. Kigg (listed in the comments), uses Unity Framework and Entity Framework too.

Julien Bérubé