Example of using child containers for scoping components

12 views
Skip to first unread message

Geoff Smith

unread,
Feb 1, 2011, 8:47:46 AM2/1/11
to Castle Project Users
Hi,

Does anyone have an example of using child containers to define the
scope of a component? (Assuming this is possible) I.e.

class A
{
public A(B b) {}
}

class B
{
public B(C c1, C c2) {}
}

class C {}

For each instance of A, I want B to use the same instance of C for c1
and c2 (I know, a little contrived). But for each new instance of A
should have a different instance of C.

Thanks!

Krzysztof Koźmic

unread,
Feb 1, 2011, 9:04:59 AM2/1/11
to castle-pro...@googlegroups.com
If all you need is a custom scope, then I think scoped lifestyle would
be a better choice.

Mauricio Scheffer

unread,
Feb 1, 2011, 9:06:06 AM2/1/11
to castle-pro...@googlegroups.com
Are you sure you want to use child containers? Didn't ContextualLifestyle solve your issue? http://stackoverflow.com/questions/4849397/sharing-instance-of-class-between-other-classes-in-castle-windsor

--
Mauricio




--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.


Geoff Smith

unread,
Feb 1, 2011, 9:11:52 AM2/1/11
to Castle Project Users
I'm also looking to using the ContextualLifestyle, but I'm running
into problems with the scope and factories. Basically, I'm not really
able to wrap all my calls to my components with the scope, so any
factories used as dependencies will no longer have access to the scope
that was used when the factory was created. Any components created by
the factory won't share the scope of the factory itself.

So it sounds like child containers are not the right approach here,
I'll keep going down the ContextualLifestyle route...

On Feb 1, 2:06 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> Are you sure you want to use child containers? Didn't ContextualLifestyle
> solve your issue?http://stackoverflow.com/questions/4849397/sharing-instance-of-class-...
>
> --
> Mauricio
>
>
>
>
>
>
>
> On Tue, Feb 1, 2011 at 10:47 AM, Geoff Smith <hotf...@gmail.com> wrote:
> > Hi,
>
> > Does anyone have an example of using child containers to define the
> > scope of a component? (Assuming this is possible) I.e.
>
> > class A
> > {
> >    public A(B b) {}
> > }
>
> > class B
> > {
> >    public B(C c1, C c2) {}
> > }
>
> > class C {}
>
> > For each instance of A, I want B to use the same instance of C for c1
> > and c2 (I know, a little contrived). But for each new instance of A
> > should have a different instance of C.
>
> > Thanks!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Castle Project Users" group.
> > To post to this group, send email to castle-pro...@googlegroups.com
> > .
> > To unsubscribe from this group, send email to
> > castle-project-u...@googlegroups.com<castle-project-users%2Bun subs...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages