且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.NET Core 类库中的依赖注入

更新时间:2023-02-16 14:33:03

关于如何管理这个问题有很多思考过程,因为最终,调用者需要为你注册你的 DI 过程.

There are many thought processes for how you manage this, as eventually, the caller will need to register your DI processes for you.

如果您查看 Microsoft 和其他公司使用的方法,您通常会使用诸如AddMyCustomLibrary"之类的方法定义扩展方法作为 IServiceCollection 的扩展方法.这里有一些讨论.

If you look at the methods used by Microsoft and others, you will typically have an extension method defined with a method such as "AddMyCustomLibrary" as an extension method off of the IServiceCollection. There is some discussion on this here.