简体   繁体   English

NInject DI 的 DI 等价物是什么?

[英]What is the DI equivalent for NInject DI?

I am currently migrating from .net4.6 which uses NInject modules.我目前正在从使用 NInject 模块的 .net4.6 迁移。 My target is to use .net6 core and its native DI.我的目标是使用 .net6 核心及其本机 DI。 While doing so I came across a statement from NInject for which I am wondering if there is an equivalent for the same in .net6 native DI?在这样做时,我遇到了 NInject 的声明,我想知道在 .net6 本机 DI 中是否有相同的声明?

this.Kernel.Bind(typeof(ICachePoolProvider<>)).To(typeof(CachePoolProvider<>));

Should I register for each type of ICachePoolProvider as shown below?我是否应该如下所示注册每种类型的 ICachePoolProvider?

services.AddSingleton<ICachePoolProvider<string>,CachePoolProvider<string>);
services.AddSingleton<ICachePoolProvider<QueueClient>,CachePoolProvider<QueueClient>);
services.AddSingleton<ICachePoolProvider<NamespaceManager>,CachePoolProvider<NamespaceManager>);

I never used NInject but from your code I expect the method you are searching for is:我从未使用过 NInject 但从您的代码中我希望您正在搜索的方法是:

services.AddSingleton(typeof(ICachePoolProvider<>), typeof(CachePoolProvider<>));

You can find a good example of an IGenericRepository here您可以在此处找到IGenericRepository的一个很好的示例

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

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