本文介绍了如何使用Func< T>内置依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用asp.net 5我希望为控制器注入Func<T>而不是T

Using asp.net 5 I'd like my controller to be injected with a Func<T>instead of T

例如:

public HomeController(Func<Interfaces.IUnitOfWork> uow)

代替

public HomeController(Interfaces.IUnitOfWork uow)

内置DI可能吗?还是我被迫移至外部DI?

Is it possible with the built-in DI or am I forced to move to an external DI?

推荐答案

据我所知,使用ASP.NET Core中的当前默认IoC容器无法像这样延迟依赖.无论如何,我还是无法使它正常工作!

As far as I'm aware deferring dependencies like this isn't possible using the current default IoC container within ASP.NET Core. I've not been able to get it working anyway!

要推迟这种依赖关系的初始化,您需要实现一个现有的,功能更丰富的IoC容器.

To defer the initialisation of dependencies like this you'll need to implement an existing, more feature rich IoC container.

这篇关于如何使用Func&lt; T&gt;内置依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:34