Hi John,

Quickly spiked this as a solution, and it appears this does not
acheive the desired solution (unless my spike is wrong of course).
Here's the spike:

[TestFixture]
public class ContainerSpike
{
    [Test]
    public void EachAggregateInstanceShouldBeCreatedWithNewDependency
()
    {
        var container = new WindsorContainer();
        container.Register(
            Component.For<MyService>(),
            Component.For<Child>().LifeStyle.Transient,
            Component.For<MyController>().LifeStyle.Transient);


        var c1 = container.Resolve<MyController>();
        var c2 = container.Resolve<MyController>();

        Assert.That(c1.Dependency, Is.SameAs(c1.MyChild.Dependency));
        Assert.That(c2.Dependency, Is.SameAs(c2.MyChild.Dependency));
        //This fails - both MyController incorrectly share the same
instance of MySerive
        Assert.That(c1.Dependency, Is.Not.SameAs(c2.Dependency));
    }

    public class MyController {

        public MyController(MyService dependency, Child child) {
            Dependency = dependency;
            MyChild = child;
        }

        public MyService Dependency { get; set; }
        public Child MyChild { get; set; }
    }


    public class Child {
        public Child(MyService dependency) {
            Dependency = dependency;
        }

        public MyService Dependency { get; set; }
    }

    public class MyService { }
}


On 23 Feb, 20:58, jsimons <[email protected]> wrote:
> Hi Christian,
>
> Why do you need a lifestyle?
> Why not register MyController as transient and Dependencies as
> singleton.
>
> Cheers
> John
>
> On Feb 24, 7:12 am, christianacca <[email protected]>
> wrote:
>
> > I would like to define a lifestyle (?) that allows me to do the
> > following
>
> > var c1 = IoC.Resolve<MyController>();
> > var c2 = IoC.Resolve<MyController>();
>
> > Assert.IsTrue(ReferenceEquals(c1.Dependency, c1.Child.Dependency));
> > Assert.IsTrue(ReferenceEquals(c2.Dependency, c2.Child.Dependency));
> > Assert.IsFalse(ReferenceEquals(c1.Dependency, c2.Dependency));
>
> > In other words, each instance of MyController should be injected with
> > a new instance of Dependency; that each object within the MyController
> > share the same instance of Dependency.
>
> > Any ideas and how this could be acheived (I am expecting the answer
> > will be create a custom ILifestyleManager - in that case I'm looking
> > for some ideas of what the implementation would look like).
>
> > Thanks in advance
> > Christian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to