1
votes

I'm having trouble manually resolving objects from my container. It seems that Windsor is not finding the suitable components even though the registration of the components goes through without problems. Specific to my case is that some components resolve fine, and others throw an exception. Notable is that constructor dependency injection works, even with dependencies I could not resolve manually.

This gets thrown when run:

Castle.MicroKernel.ComponentNotFoundException HResult=0x80131500 Message=No component for supporting the service Finance.Events.EventConductor.LoginConductor was found Source=Castle.Windsor StackTrace: at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy, Boolean ignoreParentContext) at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments) at Castle.Windsor.WindsorContainer.ResolveT at Finance.Framework.Bootstrapper.OnStartup(Object sender, StartupEventArgs e) in C:\Users\User\source\repos\Project\Project\Framework\Bootstrapper.cs:line 39 at System.Windows.Application.OnStartup(StartupEventArgs e) at System.Windows.Application.<.ctor>b__1_0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

The Code:

protected override void Configure()
{
    _windowManager = new WindowManager();
    _container = new WindsorContainer();
    _container.AddFacility<TypedFactoryFacility>();

    _container.Install(new ShellInstaller(),
                       new FrameworkInstaller(),
                       new ViewModelInstaller(),
                       new ModelInstaller(),
                       new FactoryInstaller(),
                       new RepositoryInstaller(),
                       new NHibernateInstaller());
}

Each installer registers components one by one like this:

public void Install(IWindsorContainer container, IConfigurationStore store)
{
        container.Register(Component.For<IEventAggregator>().ImplementedBy<EventAggregator>().LifestyleSingleton());
        container.Register(Component.For<ILoginConductor>().ImplementedBy<LoginConductor>().LifestyleTransient());
        container.Register(Component.For<IWindowManager>().ImplementedBy<WindowManager>().LifestyleSingleton());
        container.Register(Component.For<ILoginService>().ImplementedBy<MockLoginService>().LifestyleSingleton());
}

I'm trying to resolve my Object like this. Note that passing the LoginViewModel to the windowManager works while the line before throws an exception.

protected override void OnStartup(object sender, StartupEventArgs e)
{
    _loginConductor = _container.Resolve<LoginConductor>(); // this throws the exception.
    _windowManager.ShowWindow(_container.Resolve<LoginViewModel>()); // this does not.
}

Any help is greatly appreciated.

2
Two bits of information would help answering that: How LoginConductor is registered. How (and when) it's being resolved.Krzysztof Kozmic
Thank you for the feedback, i updated my question accordingly.e M

2 Answers

1
votes

You are seeing the error because you're trying to resolve a service for LoginConductor but you don't register a service for LoginConductor.

You are registering a component for service ILoginConductor implemented by LoginConductor.

If the above sounds confusing, and the italicised words aren't clear, there's a good primer in the documentation about it.

With that out of the way, the solution will be to align the service you resolve with the service of your dependency. Whether you keep ILoginConductor as the service or make the LoginConductor your service depends on your specific context.

1
votes

I'm assuming you've already resolved your issue - however, if it helps others:

Changing the _loginConductor part of your OnStartup method to read _loginConductor = _container.Resolve<ILoginConductor>(); (note the interface use) should work, given that ILoginConductor is what's being registered as a Service. Worked for me when I had a similar issue.