Repository Pattern in Layered Architecture

一个人想着一个人 提交于 2019-12-04 15:11:25

it's better to unilize IoC to get constructor injection, this will remove unnecessary layers' references.

I think you're missing the point and the reason why the repository pattern is so powerful. It may seem strange to call it in your presentation layer, but imagine that page needed to use a different datasource. You can just as easily swap it out with a call like: orderBL orderBL = new OrderBL(new OracleRepository());

Another alternative here is you don't pass repository references around.

Your BL can instantiate the DL when it needs to. If you have cross method calls where several operations need to happen in data then use a facade layer to sit on top of your business objects. Either way then you don't need a direct reference to a data layer repository from your presentation layer. If it makes you feel even better, pull any of your Model classes (for example Order) out into a separate "Models" project.

To avoid calling the data layer directly, you could call a function in your business layer to instatiate your repository. Your business layer could take care of the rest.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!