无法将参数传递给温莎型工厂工厂 [英] Can't pass parameter to Windsor Typed Factory Facility

查看:73
本文介绍了无法将参数传递给温莎型工厂工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IRunningTaskFactory,它已使用类型工厂工具在Windsor AsFactory()中注册。该接口具有如下所示的单个方法:

I've got a IRunningTaskFactory which is registered with Windsor AsFactory() using the Typed Factory Facility. The interface has a single method that looks like this:

RunningTask Create(ITask task);

其中RunningTask已在Windsor中注册,因为它是瞬态的,具有构造函数:

Where RunningTask is registered with Windsor as being transient has a constructor:

public RunningTask(ITask task, ITaskConfigurationFactory taskConfigurationFactory)

也向Windsor注册了ITaskConfigurationFactory。

where ITaskConfigurationFactory is registered with Windsor as well.

我遇到的问题是,当我调用Create方法并传递ITask时,以下错误:

The problem I'm running into is that when I call the Create method and pass an ITask along I get the following error:


Castle.MicroKernel.Resolvers.DependencyResolverException
:缺少依赖项。组件
Husky.nHuskyTasker.Core.Tasks.RunningTask
依赖于
Husky.nHuskyTasker.Core.Tasks.ITask,
无法解析。确保将
依赖项正确地注册为容器中的
作为服务,或者确保将
作为内联参数提供

Castle.MicroKernel.Resolvers.DependencyResolverException : Missing dependency. Component Husky.nHuskyTasker.Core.Tasks.RunningTask has a dependency on Husky.nHuskyTasker.Core.Tasks.ITask, which could not be resolved. Make sure the dependency is correctly registered in the container as a service, or provided as inline argument

从我在文档中阅读的内容来看,这应该可以正常工作。

From what I read in the documentation this should be working.

有什么想法?

推荐答案

我发现,如果您指定了虚拟对象注册具有变量实例的类型,则您的参数将毫无错误地传入:

I found that if you specify a dummy registration for the type with variable instances then your parameter gets passed in without errors:

Component.For<ITask>().ImplementedBy<AnEmptyTask>()

但是我同意,这应该可以工作,而不必进行模拟实现和额外注册。

But I agree, this should work without having to have that mock implementation and extra registration.

请注意,注册ITask将产生Windsor的副作用,即自动装配涉及该类型的任何公共属性,您可能需要取消

这篇关于无法将参数传递给温莎型工厂工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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