简体   繁体   English

使用ASP.NET 5的N层架构(MVC 6)

[英]N-Tier Architecture using ASP.NET 5 ( MVC 6 )

I was reading about ASP.NET Core features and I decide to transfer my current solution ( MVC 5 ) to MVC 6 but I got a little bit confused regarding integrated DI. 我正在阅读有关ASP.NET核心功能的内容,我决定将当前的解决方案(MVC 5)转移到MVC 6,但我对集成DI有点困惑。 Currently I have this architecture 目前我有这种架构

目前的架构

CemaManager ( representative layer ) has reference to Helpers, Resource, ViewModel and BLL. CemaManager(代表层)引用了Helpers,Resource,ViewModel和BLL。 Bll has reference to ViewModel, Database and DLL. Bll引用了ViewModel,Database和DLL。 Dll has reference to Database. Dll引用了Database。

Typical N-tier architecture using DI and Repository pattern. 使用DI和存储库模式的典型N层架构。

When I investigate MVC6 there is startup.cs where DI initialize. 当我调查MVC6时,有启动,其中DI初始化。 That means if I want to separate BLL and DAL they will have all reference to MVC6 and all logic will go thru that layer? 这意味着如果我想分离BLL和DAL,它们将全部引用MVC6并且所有逻辑都将通过该层? By the time It's gonna be heavy and hard to maintain and scale or am I wrong? 到时候它会变得沉重,难以维持和扩展,还是我错了?

Is there any way to export startup.cs or DI method to another layer? 有没有办法将startup.cs或DI方法导出到另一层? Maybe somebody know any articles to read or examples? 也许有人知道要阅读的文章或例子?

Personally I have a few things I would change about the overall structure, but I'm guessing a full design review isn't really what you're asking for. 就个人而言,我会对整体结构有一些改变,但我猜测完整的设计评审并不是你所要求的。 ON your actual question, no - your other layers do not need to reference MVC. 在您的实际问题上,不 - 您的其他图层不需要引用MVC。

For most any application, IoC needs to be configured and initialized in the presentation layer. 对于大多数应用程序,需要在表示层中配置和初始化IoC。 Ultimately your presentation layer needs a reference chain (direct or indirect references) to everything you want to register, but this has always been true. 最终,您的表示层需要一个参考链(直接或间接引用)到您想要注册的所有内容,但这一直都是正确的。

You are already referencing Helpers, Resource, ViewModel, and BLL so you can easily register implementations for the interfaces in those layers. 您已经引用了Helpers,Resource,ViewModel和BLL,因此您可以轻松地在这些层中注册接口的实现。 You could also add a reference to DLL to register implementations from that layer. 您还可以添加对DLL的引用以注册该层的实现。

You can also go the indirect route and add a class in each layer which takes a reference to your IoC container and handles its own registration. 您还可以使用间接路由并在每个层中添加一个类,该类引用您的IoC容器并处理其自己的注册。 In Autofac this is done using modules but there are equivalent ways of accomplishing the same thing using other IoC containers. 在Autofac中,这是使用模块完成的,但是使用其他IoC容器有相同的方法来完成相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM