0

i have used the repo pattern in my web forms application in the following way

UI Layer:

it contains the code behind files in which the controls are being binded and user actions like insert update etc are catered for

the UI Layer calls the

Repository Layer:

it contains the repository classes inheriting the GenericRepo:IGeneric

and the

Data Layer:

it contains the EF generated domain classes

the layers are strict for the time being that is the UI layer calls the Repo layer and it in turns call the data layer to fetch the data.

Problem:

now the problem im facing is that if for example i need a list of products on the Products.aspx page i need to do some thing like

IProductRepo pr = new ProductRepo();

IList<Products> lstProducts = pr.GetAll();

i dont want to add the reference of Data Layer to the UI layer in order to access the domain entities i.e generated by the EF

what are my options? please guide me to the right path

regards.

4

1 回答 1

1

在我看来,你错过了一层。我会这样构建它:

UI                |
-----             |
**Domain**        |   Domain classes
-----             |
DAL (Repository)  |

这样,您的逻辑位于单独的层中,并且您的 DAL 完全隐藏在您的逻辑和域模型中。

解决此问题的另一种方法是使用依赖注入。这样你就可以定义一些接口并且只保留对接口的引用。使用依赖容器,您可以十个将这些引用与真实类型联系起来。

我首选的 DI 容器是例如Ninject

于 2013-05-10T12:43:49.240 回答