views:

439

answers:

2

For example I have two interfaces: ICustomerService and IOrderService which each has a couple of functions like GetCustomer, GetOrder, etc.

I want one class to implement both interfaces: Server.

How does Castle Windsor respond to this? Is it possible in the first place? When I resolve the Server object based on one of the two interfaces, will I get the same object? What happens when I have a constructor that has both interfaces in its parameters? Will there still be one object constructed.

assuming the LifeStyle is left to its default: Singleton.

+3  A: 

Did you check this post?

Here also

Forum post also has info on this

Ric Tokyo
Yes, I've checked them. First post isn't the same as my question, error in second post is caused by an old version of Castle. The code file from the post containing the tests is useful, it shows that only one object is used.
Gerrie Schenck
The forum post has the solution
Mauricio Scheffer
A: 

I keep a solution on my system with NUnit and Windsor configured, so I can easily answer questions like yours. Quick test:

[Test]
public void CheckSingleton()
{
 var container = new WindsorContainer();
 container.AddComponentWithLifestyle("service.SomeService", typeof(ISomeService), typeof(ConcreteType), LifestyleType.Singleton);
 container.AddComponentWithLifestyle("service.AnotherService", typeof(IAnotherService), typeof(ConcreteType), LifestyleType.Singleton);

 var someService = container.Resolve<ISomeService>();
 var anotherService = container.Resolve<IAnotherService>();

 Assert.AreSame(someService, anotherService);
}

=> FAILED

therefore: Sorry, it seems like there is a singleton per service registration.

mookid8000
Nope, check the forum post on the first answer
Mauricio Scheffer
I think the forum post seems to be about a problem in the fluid registration on one particular revision of the Castle trunk ... or? In my test, I CAN resolve both services, but they do NOT point to the same instance of the concrete class.
mookid8000
Btw I get the same result when I resolve another service that depends on both interfaces - they are still pointing to difference instances.
mookid8000