本文介绍了可以从 dotnet core 1 访问嵌套引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 dotnet core 为我的 Web 项目创建了业务和数据访问层.我在业务层添加了数据访问引用,并在 UI(Web 项目)层引用了业务层.

I have created Business and DataAccess Layer for my web project using dotnet core.I have added Data access reference in Business layer and referenced the business layer in UI (web project) layer.

我看到了,我可以从我的 UI (web) 项目访问我的数据访问层.我真的很想知道,它可能会导致违反任何应用程序设计.

I seen, I am able to access my Data access layer from my UI (web) project. I am really wondering, It can lead to violation of any application design.

感谢帮助,如果有人遇到此问题以及如何限制从 UI 访问数据访问层.

Appreciate help, if anybody come across this and how to restrict access to data access layer from UI.

推荐答案

是的,间接依赖也是一种依赖.

Yes, an indirect dependency is a dependency too.

并且您的顶级 (MVC) 项目必须直接或间接引用所有内容,以便加载所有模块.并设置依赖注入.

And your toplevel (MVC) project has to reference everything, direct or indirect, in order to get all modules loaded. And to set up the dependency injection.

您可以通过在单独的项目中引入接口层来获得更好的分离.例如 IBusinessClass 和 IDataAccessClass.

You can get better separation by introducing an interfaces layer in a separate project. For example IBusinessClass and IDataAccessClass.

这适用于除主项目之外的所有内容,因此如果您希望与示例进行这种特殊分离,请将控制器移至单独的项目并仅依赖于 IBusiness 接口.虽然我不确定它是如何与 MVC 的约定配合使用的.

That works for everything but the main project so if you want this particular separation from your example, move your Controllers to a separate project and depend that on the IBusiness interfaces only. Though I'm not sure how that works with MVC's conventions.

这篇关于可以从 dotnet core 1 访问嵌套引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 12:42