简单明了,它的用例是什么Orchard.Environment.Work<>
类定义于Orchard\Environment\WorkContextModule.cs
?
它可以在几个地方找到,例如
private readonly Work<IContainerService> _containerService;
public Shapes(Work<IContainerService> containerService) {
_containerService = containerService;
...
是否是为了延迟解决IContainerService
?
The Work
类用于延迟加载依赖注入。实例化类时不会解决依赖关系,而是仅在调用类时解决依赖关系Value
财产:
private readonly IMyService _myService;
private readonly IMyOtherService _myOtherService;
public MyClass(Work<IMyService> myService, IMyOtherService myOtherService) {
// Just assign the Work class to the backing property
// The dependency won't be resolved until '_myService.Value' is called
_myService = myService;
// The IMyOtherService is resolved and assigned to the _myOtherService property
_myOtherService = myOtherService;
}
现在只有当_myService.Value
被调用时,IMyService 由依赖解析器解析,这为您提供了延迟加载依赖注入的工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)