Let me rephrase

using (WindsorContainer container = new WindsorContainer())
{
   container.Register(
       Castle.MicroKernel.Registration.Component.For<IMyInterface>().
           Named("Instance").
           ImplementedBy<MyClass>().
           LifeStyle.Transient,
       Castle.MicroKernel.Registration.Component.For<IMyInterface>().
           ImplementedBy<MyClass>().
           LifeStyle.Singleton
       );

   var singleton = container.Resolve<IMyInterface>();
   var singleton1 = container.Resolve<IMyInterface>();

   var instance = container.Resolve<IMyInterface>("Instance");
   var instance1 = container.Resolve<IMyInterface>("Instance");

   Assert.AreSame(singleton, singleton1);
   Assert.AreNotSame(instance, instance1);
}

Windsor will use the firstly registered Component of a specific service
always (not always but in general - unless you're using handlerselector)
   container.Register(
       Castle.MicroKernel. Registration.Component.For<IMyInterface>().
           Named("Instance").
           ImplementedBy<MyClass>().
           LifeStyle.Transient,

This is the firstly registered component, and it is transient

   var singleton = container.Resolve<IMyInterface>();
   var singleton1 = container.Resolve<IMyInterface>();

Those two are actually not singletons but instances of the transient
component.

Is that clear?


Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike




On Sun, May 24, 2009 at 11:55 AM, vdhant <[email protected]> wrote:

>
> Hi Tuna
> Thanks for the reply.
> Sorry to say but what you are saying doesn't quite make sense to me...
>
> Test Case 1:
>
> Assert.AreSame(singleton, singleton1);
>    Assert.AreNotSame(instance, instance1);
>
>
> On May 24, 5:28 pm, Tuna Toksoz <[email protected]> wrote:
> > Test Case 1: You're using Transient so they won't be same at all. You'll
> get
> > different instances
> > Test Case 2: Fails because when you ask IMyInterface, you'll get the
> > component registered first.
> > Test Case 3 is what you see from above reasons.
> >
> > Tuna Toksöz
> > Eternal sunshine of the open source mind.
> >
> >
> http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike
> >
> > On Sun, May 24, 2009 at 9:35 AM, vdhant <[email protected]> wrote:
> >
> > >    var singleton = container.Resolve<IMyInterface>();
> > >    var singleton1 = container.Resolve<IMyInterface>();
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Development List" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to