依赖注入/国际奥委会工作流基础4 [英] Dependency injection / IoC in Workflow Foundation 4

查看:109
本文介绍了依赖注入/国际奥委会工作流基础4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在你的工作流活动使用DI?如果是,怎么样?

Is it possible to use DI in your workflow activities? and if yes, how?

例如,如果你有一个像

public sealed class MyActivity : CodeActivity
{
    public MyClass Dependency { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
        Dependency.DoSomething();
    }
}



如何设置依赖

(我用Spring.Net)

(I'm using Spring.Net)

推荐答案

工作流程不使用IOC容器。它使用你来自哪里,通过上下文工作流扩展添加依赖于工作流运行时为扩展和工作流活动和检索这些服务的ServiceLocator模式。

Workflow doesn't use an IOC container. It uses the ServiceLocator pattern where you add dependencies to the workflow runtime as extensions and workflow activities and retrieve these services from the workflow extensions through the context.

一个服务定位和IOC模式是类似的,具有在解耦依赖性相同的目的。该apporach不同的是,虽然在IOC容器推依赖关系而服务定位是用来拉的依赖了。

A ServiceLocator and IOC pattern are similar and have the same purpose in decoupling dependencies. The apporach is different though in an IOC container pushing dependencies in while a ServiceLocator is used to pull dependencies out.

举例活动:

public class MyBookmarkedActivity : NativeActivity
{
    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        base.CacheMetadata(metadata);
        metadata.AddDefaultExtensionProvider<MyExtension>(() => new MyExtension());
    }

    protected override void Execute(NativeActivityContext context)
    {
        var extension = context.GetExtension<MyExtension>();
        extension.DoSomething();

    }
}



MyExtension类是这里的扩展它没有基类或接口的要求。

The MyExtension class is the extension here and it has no base class or interface requirements.

这篇关于依赖注入/国际奥委会工作流基础4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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