Question

public interface ISomething
{
    string SomeMethod(string arg);
}


public class Something : ISomething
{
    public Something(Type type)
    {
        // initialization using type argument
    }

    public Something(string name)
    {
        // initialization using name argument
    }

    public string SomeMethod(string arg)
    {   
        // do something
    }
}       


public class SomethingElse : ISomethingElse
{
    public SomethingElse(ISomething something)
    {
        // ....
    }
}         


public class WindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Component.For<ISomething>().ImplementedBy<Something>().Named("Something").LifestyleSingleton());
    }
}

( For brevity I'm leaving out the standard Windsor initialization code. )

But when an instance of ISomethingElse is created ( perhaps due to ISomethingElse being injected in some other class ), Windsor can't resolve the ISomething constructor parameter because it doesn't know what to supply for the type argument.

Castle.MicroKernel.Handlers.HandlerException was unhandled by user code
  HelpLink=groups.google.com/group/castle-project-users
  HResult=-2146233088
  Message=Can't create component 'Something' as it has dependencies to be satisfied.

'Something' is waiting for the following dependencies:
- Service 'System.Type' which was not registered.
- Parameter 'name' which was not provided. Did you forget to set the dependency?
Was it helpful?

Solution

Have a look here, this shows how to add dependencies which are not services (thus cannot be resolved by the container)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top