Workflow Foundation 4 中的依赖注入/IoC
是否可以在您的工作流程活动中使用 DI?如果是,怎么办?
例如,如果您有一个活动,例如
public sealed class MyActivity : CodeActivity
{
public MyClass Dependency { get; set; }
protected override void Execute(CodeActivityContext context)
{
Dependency.DoSomething();
}
}
如何设置Dependency
?
(我正在使用Spring.Net)
Is it possible to use DI in your workflow activities? and if yes, how?
For example if you have an activity like
public sealed class MyActivity : CodeActivity
{
public MyClass Dependency { get; set; }
protected override void Execute(CodeActivityContext context)
{
Dependency.DoSomething();
}
}
how can i set Dependency
?
(I'm using Spring.Net)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
工作流不使用 IOC 容器。它使用 ServiceLocator 模式,您可以将依赖项作为扩展和工作流活动添加到工作流运行时,并通过上下文从工作流扩展中检索这些服务。
ServiceLocator 和 IOC 模式很相似,并且在解耦依赖方面具有相同的目的。不过,在 IOC 容器中推送依赖项而使用 ServiceLocator 拉出依赖项时,方法是不同的。
示例活动:
MyExtension 类是此处的扩展,它没有基类或接口要求。
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.
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.
Example activity:
The MyExtension class is the extension here and it has no base class or interface requirements.