Orchard CMS 中的 Work<> class 是什么?

What is the Work<> class for in Orchard CMS?

简单明了,Orchard\Environment\WorkContextModule.cs中定义的Orchard.Environment.Work<>class的用例是什么?

它可以在几个地方找到,比如

private readonly Work<IContainerService> _containerService;

public Shapes(Work<IContainerService> containerService) {
  _containerService = containerService;
...

是为了延迟解决IContainerService吗?

Work class 用于延迟加载依赖注入。实例化 class 时不解决依赖关系,但仅在调用 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 才会被依赖解析器解析,这为您提供了延迟加载依赖注入的工作。