I have hit a problem in my use of Castle.Windsor's TypedFactoryFacility concept, and not sure how to resolve it (or if I can).
I have a ViewModel defined like so;
public class MyViewModel : IMyViewModel
{
// constructor which I aim to access through the factory
public MyViewModel(
ISomeContainerResolvableDependency a,
ISomePassedInDependency b)
{ ... }
}
And a corresponding factory interface defined like;
public interface IMyViewModelFactory
{
IMyViewModel Create(ISomePassedInDependency a);
void Release(IMyViewModel vm);
}
However, when I try to call the factory with a valid, non-null instance of ISomePassedInDependency
like so;
ISomePassedInDependency o = new SomePassedInDependency();
IMyViewModelFactory factory = IoC.Get<IMyViewModelFactory>();
IMyViewModel viewModel = factory.Create(o);
I get an Exception stating that Castle Windsor could not resolve the dependency from IMyViewModel
on ISomePassedInDependency
. In this case, I am supplying the ISomePassedInDependency
instance, and only want the facility to resolve ISomeContainerResolvableDependency
for me.
If I change the constructor definition to accept a value type which I pass in (int
, for example) instead of an ISomePassedInDependency
instance, the factory call works. So, it seems that there is an assumption inside Castle Windsor that all reference types will be container resolved and anything else will not?
Is there some way to make this work?