How can I register a singleton type with multiple services?

6 views
Skip to first unread message

Michael Sevestre

unread,
Dec 19, 2012, 1:22:27 PM12/19/12
to castle-pro...@googlegroups.com
Hi folks,

I am in the process of updating from 2.5 to 3.1. I am facing a major issue because of breaking change introduced in the 3.0 version in the way container.ResolveAll<> works.

I found that thread is  "https://groups.google.com/forum/?fromgroups=#!topic/castle-project-users/oZcj_0xsKHgl" saying that one could use multiple service registration. It works fine for transcient object.
However for singleton, I am not getting the expected behavior

Here is a test that reproduce my issue
         container.Register(Component.For<ITask>().ImplementedBy<Task>().Named("task1").LifeStyle.Is(LifestyleType.Singleton));
         container.Register(Component.For<IBaseTask>().ImplementedBy<Task>().Named("task2").LifeStyle.Is(LifestyleType.Singleton));

[Observation]
      public void resolve()
      {
         var task1= container.Resolve<ITask>();
         var task2 = containerResolve<IBaseTask>();

         Assert.AreEqual(task1,task2);
      }

Basically, I get to different instances of the object Task that was registered as Singleton.
Is it the intended behavior? If yes, what should I do in order to fall back to the behavior I am relying on from the 2.5 Version (aside from sticking with the old version?)

Thanks for your feedback,

Cheers,
Michael
Reply all
Reply to author
Forward
0 new messages