具有约定的内置依赖项注入 [英] Built-in dependency injection with conventions

查看:76
本文介绍了具有约定的内置依赖项注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不注册服务的情况下注入服务?我的意思是,过去一些DI框架自动为 IService 注册了 Service .

How to inject services without registering them? I mean in the past some DI frameworks automatically registered Service for IService.

我处于一种状态,那里有很多服务,而基本上每一个服务都要注册都是一件痛苦的事情.那么asp.net核心默认的DI框架支持此功能吗?

I'm in a situation where I have a dozen of services and basically registering every single one is a pain in the ass. so is this supported in asp.net core default DI framework?

推荐答案

现成的DI不支持它,也不打算这样做.内置的IoC容器在设计上保持简单,从而允许在大多数情况下都可以使用基本的依赖项注入.

The out-of-the-box DI doesn't support it and do not intend to do so. The built-in IoC Container is kept simple by design, to allow basic dependency injection which works for most cases.

如果要使用高级功能,例如按约定注册,程序集扫描或装饰器支持,则必须使用第三方方IoC容器,例如Autofac,SimpleInjector,Castle Windsor.

If you want advanced features like registering by convention, assembly scanning or decorator support, you have to use 3rd party IoC container like Autofac, SimpleInjector, Castle Windsor.

这篇关于具有约定的内置依赖项注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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