Orchard CMS中的Work 类是什么?
简单明了, Orchard\Environment\WorkContextModule.cs
定义的Orchard.Environment.Work
类的用例是什么?
它可以在几个地方找到
private readonly Work _containerService; public Shapes(Work containerService) { _containerService = containerService; ...
是否延迟解决IContainerService
?
Work
类用于延迟加载依赖项注入。 实例化类时不依赖于依赖关系,但仅在调用Value
属性时才解决:
private readonly IMyService _myService; private readonly IMyOtherService _myOtherService; public MyClass(Work 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,这使您可以处理延迟加载依赖项注入。