Windsor Container AddComponentInstance bug

I am reliably informed that this error has been fixed on the trunk but it is most definitely still occurring in the assembly version that I am referencing. Assuming that others arent working from the latest version of the trunk I thought it would be worth recording here both the bug and the workaround.

In my tests I typically attempt to mock my dependencies. Then I inject the mock into the container so that it is retrievable by my calling code. But alas, calling AddComponentInstance with the following method signature failed.

AddComponentInstance<IExceptionHandler<NotImplementedException>>(mockHandler);

The error reported :

No component for supporting the service Project.Web.Controllers.ExceptionHandlers.IExceptionHandler`1[[System.NotImplementedException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] was found Castle.MicroKernel.ComponentNotFoundException

The workaround is to simply use a different method signature which assumedly under the covers registers the component and the instance correctly. See:

AddComponentInstance<IExceptionHandler<NotImplementedException>>( typeof(IExceptionHandler<NotImplementedException>), mockHandler);

Ta da.

February 14, 2008 10:12 by steven.burman
E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed