简单明了,Orchard.Environment.Work<>该类定义的用例是Orchard\Environment\WorkContextModule.cs什么?
它可以在几个地方找到
private readonly Work<IContainerService> _containerService;
public Shapes(Work<IContainerService> containerService) {
_containerService = containerService;
...
Run Code Online (Sandbox Code Playgroud)
这是为了延迟解决IContainerService?
该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;
}
Run Code Online (Sandbox Code Playgroud)
现在只有在_myService.Value被调用时,依赖性解析器才能解析IMyService,这使您可以进行延迟加载依赖注入.