Windsor RC3: Can't resolve instance from Kernel

144 views
Skip to first unread message

Derick Bailey

unread,
Jan 28, 2008, 9:32:44 AM1/28/08
to Castle Project Users
Hello,

I'm trying to register an instance of a component in my unit tests (a
mock or a standard instance) and the resolution is failing.

I'm using Windsor RC3 with Visual Studio 2008 / .NET 3.5 / C#

using Castle.Windsor;
using NUnit.Framework;
using Rhino.Mocks;

namespace SigmaDelta.Test
{
[TestFixture]
public class ShowDialogCommandFixture
{
[Test]
public void TestDynamicMock()
{
MockRepository mockRepository = new MockRepository();
IShowDialogCommand showDialogCommand =
mockRepository.DynamicMock<IShowDialogCommand>();

IWindsorContainer container = new WindsorContainer();

container.Kernel.AddComponentInstance<IShowDialogCommand>(showDialogCommand);

Assert.AreSame(showDialogCommand,
container.Resolve<IShowDialogCommand>());
}

[Test]
public void TestStandardInstance()
{
MockRepository mockRepository = new MockRepository();
IShowDialogCommand showDialogCommand = new ShowDialogCommand();

IWindsorContainer container = new WindsorContainer();

container.Kernel.AddComponentInstance<IShowDialogCommand>(showDialogCommand);

Assert.AreSame(showDialogCommand,
container.Resolve<IShowDialogCommand>());
}
}

public class ShowDialogCommand : IShowDialogCommand
{

}

public interface IShowDialogCommand
{
}
}

the above unit tests produce these errors:

Error 1 TestCase
'SigmaDelta.Test.ShowDialogCommandFixture.TestDynamicMock'
failed: Castle.MicroKernel.ComponentNotFoundException : No component
for supporting the service SigmaDelta.Test.IShowDialogCommand was
found
at Castle.MicroKernel.DefaultKernel.get_Item(Type service)
at Castle.Windsor.WindsorContainer.Resolve(Type service)
at Castle.Windsor.WindsorContainer.Resolve[T]()
at SigmaDelta.Test.ShowDialogCommandFixture.TestDynamicMock() in X:
\SigmaDelta\Trunk\Code\SigmaDelta\SigmaDelta.UnitTests\MVP
\Class1.cs:line 19 X:\SigmaDelta\Trunk\Code\SigmaDelta
\SigmaDelta.UnitTests\MVP\Class1.cs 19

Error 2 TestCase
'SigmaDelta.Test.ShowDialogCommandFixture.TestStandardInstance'
failed: Castle.MicroKernel.ComponentNotFoundException : No component
for supporting the service SigmaDelta.Test.IShowDialogCommand was
found
at Castle.MicroKernel.DefaultKernel.get_Item(Type service)
at Castle.Windsor.WindsorContainer.Resolve(Type service)
at Castle.Windsor.WindsorContainer.Resolve[T]()
at SigmaDelta.Test.ShowDialogCommandFixture.TestStandardInstance()
in X:\SigmaDelta\Trunk\Code\SigmaDelta\SigmaDelta.UnitTests\MVP
\Class1.cs:line 31 X:\SigmaDelta\Trunk\Code\SigmaDelta
\SigmaDelta.UnitTests\MVP\Class1.cs 31


....

Am i doing something wrong? or is this a problem in Windsor/RC3?

Roelof Blom

unread,
Jan 28, 2008, 9:51:42 AM1/28/08
to castle-pro...@googlegroups.com
Hi,

I am not sure if it's a bug, but it looks like it because this call behaves differently on trunk.

Three workarounds:
  1. container.Kernel.AddComponentInstance<IShowDialogCommand>(typeof(IShowDialogCommand), showDialogCommand);
  2. container.Kernel.AddComponentInstance(typeof(IShowDialogCommand).FullName, typeof(IShowDialogCommand), showDialogCommand);
  3. Use the trunk :-)
-- Roelof.

Derick Bailey

unread,
Jan 28, 2008, 10:01:01 AM1/28/08
to Castle Project Users
I'll go with option #1 for now. Any idea when RC4 is going to be
released?

Reply all
Reply to author
Forward
0 new messages