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.
LoginConductor
is registered. How (and when) it's being resolved. – Krzysztof Kozmic