根据公约的ASP.NET结合5/6 MVC [英] Convention based binding in ASP.NET 5 / MVC 6

查看:141
本文介绍了根据公约的ASP.NET结合5/6 MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是可能的手动注册依赖关系:

It is possible to register dependencies manually:

services.AddTransient<IEmailService, EmailService>();
services.AddTransient<ISmsService, SmsService>();

当有太多的依赖关系,则难以手动注册的所有依赖

When there are too much dependencies, it becomes difficult to register all dependencies manually.

什么是实现基于MVC中绑定6公约的最佳方式(测试版7)?

What is the best way to implement a convention based binding in MVC 6 (beta 7)?

PS在以前的项目中,我用 Ninject ninject.extensions.conventions 。但我不能找到一个Ninject适配器MVC 6。

P.S. In previous projects I used Ninject with ninject.extensions.conventions. But I can't find a Ninject adapter for MVC 6.

推荐答案

没有,有一个在ASP整批不支持.NET 5内置DI库。作为事实上,有建立大型固体应用需要许多特性,但在内置不包括的-in DI库。

No, there is no support for batch registration in the ASP.NET 5 built-in DI library. As a matter of fact, there are many features that are needed to build large SOLID applications, but are not included in the built-in DI library.

所包含ASP.NET DI库主要是为了延长ASP.NET系统本身。对于您的应用程序,你是最好的时候使用成熟的DI库在那里之一,保持你的配置独立从用于配置ASP.NET系统本身的配置。
这消除了一个适配器的需求。

The included ASP.NET DI library is primarily meant to extend the ASP.NET system itself. For your application, you are best off using one of the mature DI libraries out there, and keep your configuration separate from the configuration that used to configure the ASP.NET system itself. This removes the need for an adapter.

这篇关于根据公约的ASP.NET结合5/6 MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆