gpt4 book ai didi

c# - Orchard CMS 中的 Work<> 类是什么?

转载 作者:行者123 更新时间:2023-11-30 20:20:32 26 4
gpt4 key购买 nike

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

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

private readonly Work<IContainerService> _containerService;

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

是否延迟解析IContainerService

最佳答案

Work 类用于延迟加载依赖注入(inject)。实例化类时不解决依赖关系,但仅在调用 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 才会被依赖解析器解析,这让您可以进行延迟加载依赖注入(inject)。

关于c# - Orchard CMS 中的 Work<> 类是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36307200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com