I'm using Castle Windsor as an IoC container, and I want to resolve an object depending on another:
public MyService : IService
{
public MyService(MyObject obj)
{
}
}
Where resolving with:
var service1 = container.Resolve<IService>( new { obj = obj1 });
var service2 = container.Resolve<IService>( new { obj = obj1 });
var service3 = container.Resolve<IService>( new { obj = obj2 });
I want service1 to be the same as service2 (same reference), and service3 different. So I need a lifestyle different than Singleton or Transient. The same object should be returned as long as the obj parameter is the same (by reference).
Do you know how to achieve that?
obj
seems to be). Passing in values into theResolve
method is a design smell. IfIService
is a factory, pass inobj
in to the factoriesCreateXXX
method, since it is clearly part of the factories contract. – StevenILifestyleManager
, which would probably save you tons of time. – Steven