Can't pass parameter to Windsor Typed Factory Facility
Asked Answered
T

2

7

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);

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

public RunningTask(ITask task, ITaskConfigurationFactory taskConfigurationFactory)

where ITaskConfigurationFactory is registered with Windsor as well.

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 : 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.

Thoughts?

Teevens answered 24/3, 2011 at 16:14 Comment(6)
For now I've written my own RunningTaskFactory which gets an IKernel and calls it with the task being provided and that works fine. According to the docs I'm not doing anything that the Factory shouldn't be doing itself..Teevens
You'll still need to explicitly register a component for ITask as well, I think...Eratosthenes
I can't. There are N implementations of ITask and I don't want them to have access to my container.Teevens
They don't need to have access to the container (they shouldn't), but the container needs to have access to them/know about them.Eratosthenes
if they are registered with the server they have access to the server by adding IKernel kernel to their constructor.Teevens
Did you check that task is not null ? And can there be a mismatched of ITask (possibly from Microsoft.Build.Framework)Crossbow
C
1

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.

Note that registering ITask will have the side-effect of Windsor auto-wiring any public properties involving that type, which you may need to suppress

Caprifoliaceous answered 5/5, 2012 at 16:10 Comment(1)
@ShaneCourtrille: this is a dirty hack and must not be marked as answer. Correct answer is another one.Pigeonwing
C
7

I had the same problem (runtime parameter into a typed factory not resolving) and it turned out to be because the parameter name on my factory and the name of the constructor parameter on the actual class were different, so when calling .Create() on the typed factory it couldn't resolve my parameter.

This thread solved by issue: Can Castle.Windsor TypedFactoryFacility construct a type with only some ref arguments passed inline?

Not obvious, but it makes sense.

Charolettecharon answered 6/5, 2015 at 11:35 Comment(1)
You, sir, just saved my sanity. Please have +1.Lurlenelurline
C
1

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.

Note that registering ITask will have the side-effect of Windsor auto-wiring any public properties involving that type, which you may need to suppress

Caprifoliaceous answered 5/5, 2012 at 16:10 Comment(1)
@ShaneCourtrille: this is a dirty hack and must not be marked as answer. Correct answer is another one.Pigeonwing

© 2022 - 2024 — McMap. All rights reserved.