依赖注入的自定义工作流活动 [英] Dependency injection in custom workflow activity

查看:306
本文介绍了依赖注入的自定义工作流活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了一个工作流标准应用。客户可以自定义设计的工作流程。现在,我们正在为特定客户做一些定制的活动。这个自定义活动是针对一个接口业务层进行通信。我怎么给接口,接口的实现?

I have a standard application that has a workflow. The customer can customize the workflow in the designer. Now we are making some custom activities for a specific customer. The custom activity is communicating against the business layer by a interface. How do I give the interface an implementation of that interface?

,该标准应用程序不知道有关该接口的接口和实现,因为它是为特定的客户定制代码这是非常重要的。的活性通过标准流程发现使作品已经。

It is very important that the standard application doesn't know about the interface and implementation of that interface because it is custom code for that specific customer. The activity is found by standard workflow so that works already.

我看到了很多关于扩展的信息,但我真的不知道它是如何工作的。

I see a lot of information about extensions but I don't really know how it works.

自定义活动

public sealed class GetDealerDetails : CodeActivity
{
    /////// <summary>
    /////// The dealer controller with all the businesslogic.
    /////// </summary>
    ////private readonly IDealerController _dealerController;

    [Inject]
    public IDealerController DealerController { private get; set; }

    ////public GetDealerDetails()
    ////{

    ////}

    ////[Inject]
    ////public GetDealerDetails(IDealerController dealerController)
    ////{            
    ////    _dealerController = dealerController;
    ////}

    protected override void Execute(CodeActivityContext context)
    {
        Dealer dealer = DealerController.GetDealerDetails(5);
    }
}



我用Ninject在我的标准应用程序。我试图用构造器注入和财产注入,但它不工作。在 DealerController 停留

修改
的代码的其余部分可以在这里找到:注入自定义在标准的应用程序代码

推荐答案

导入的是,你必须使用工作流应用程序包装我ninject提供。只有这样我可以建立起来的活动。诀窍是:你不能使用构造函数注入与自定义工作流活动。活动是WF很特别。通常当你有编码的工作流程,你建立他们我们在一个lambda表达式中,然后执行懒惰新的运营商。所以,我的ninject扩展只能工作它的魔力,当活动已经建立起来了。因此,您需要在您的活动树的根活动传递ninject的工作流应用程序。这并在内部解决,整个活动树UND注入均装饰有进样属性的所有属性。

Import is that you have to use the workflow application wrapper I provide with ninject. Only with that I can build up the activities. The trick is the following: you cannot use constructor injection with custom workflow activities. Activities are very special in WF. Usually when you have coded workflow you build them up we the new operator in a lambda expression which is then lazy executed. So my ninject extension can only work its magic when the activities are already built up. Therefore you need to pass in the root activities of your activity tree in the workflow application of ninject. This does then internally resolve the whole activity tree und injects all properties which are decorated with the inject attribute.

但实际的问题是在我现在已经固定在库中的缺陷。所述BookmarkInfo装饰假定的范围信息总是被设置,这是并非如此。

But your actual problem was a bug in the library which I have fixed now. The BookmarkInfo decorator assumed that the scope info is always set and this wasn't the case.

这篇关于依赖注入的自定义工作流活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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