什么是工作和LT;>在果园CMS类? [英] What is the Work<> class for in Orchard CMS?

查看:211
本文介绍了什么是工作和LT;>在果园CMS类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单明了,什么是 Orchard.Environment.Work<的使用情况;> 中定义的类 Orchard\Environment\ WorkContextModule.cs

Plain and simple, what is the use case of the Orchard.Environment.Work<> class defined in Orchard\Environment\WorkContextModule.cs?

可以在几个地方找到像

private readonly Work<IContainerService> _containerService;

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



是它 IContainerService <迟发分辨率/ code>?

Is it for delayed resolution of IContainerService?

推荐答案

工作类是懒加载依赖注入。实例化类依赖性时,没有得到解决,但在调用属性,只有当:

The Work class is for lazy loading dependency injection. The dependency is not resolved when instantiating the class, but only when calling the Value property:

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得到由依赖解析器,它给你一个懒加载依赖注入的工作解决了。

Now only when _myService.Value is called, the IMyService gets resolved by the Dependency resolver, which gives you the working of a lazy loading dependency injection.

这篇关于什么是工作和LT;&GT;在果园CMS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆