Thanks Germán,

I thought someone would have come across this problem before.

Using StructureMap, in a given "build-up" the same child object is returned 
where referenced by different parents - ie within the same buildup. For that 
application, each use-case was wrapped in a orchestration class. Resolving an 
instance of that class created a single new session that was passed to each 
repository.

Remembering the type of the handler that initiates the resolution chain along 
with the instance just created, then caching that instance seems a good 
workaround. For a quick fix I've used a singleton and manually created new 
sessions as required. But that isn't going to work in a multi threaded 
environment.

I was hoping for a "singleton per build up"  where the IoC framework keeps 
track of "default" service resolutions and returns the same instance for each 
resolution.

SB


From: Germán Schuager [mailto:[email protected]]
Sent: Thursday, 18 November 2010 1:44 PM
To: [email protected]
Cc: Simon Bateman
Subject: Re: How to configure Castle Windsor to use the same grand-child 
objects on a single build-up.

Although I don't use this approach anymore for managing NH sessions, maybe you 
can take some ideas from these posts:
http://blog.schuager.com/2008/11/custom-windsor-lifestyle.html
http://blog.schuager.com/2009/03/rich-client-nhibernate-session.html

On Wed, Nov 17, 2010 at 8:13 PM, SimonB 
<[email protected]<mailto:[email protected]>> wrote:
Castle Windsor creates multiple instances of grand child objects using
transient lifestyle.

I have an object graph:
- Object A has a dependency on C1 and C2.
- C1 and C2 both have a dependency on GC.
- I need C1 and C2 to have the same GS in a given build up.

Using StructureMap a single instance of GC is created and passed to
both C1 and C2.
Using Castle.Windsor a new instance of GC is created for C1 and C2 -
ie 2 instances.

In my case GS is managing a nHibernate session, and C1 and C2 are
repositories used by domain class A.

Castle Windsor is returning 2 sessions causing cross session data
errors.

Does anyone know how to get access to or use the build up context so
the instances of child objects can be cached like structure map.

Thanks,

SB

--
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]<mailto:[email protected]>.
To unsubscribe from this group, send email to 
[email protected]<mailto:castle-project-users%[email protected]>.
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

This email and any accompanying documents are confidential, may be privileged 
and are intended only for the use of the intended recipient. If you are not the 
intended recipient, any use, dissemination, forwarding, printing or copying of 
this email and any accompanying documents is strictly prohibited. Please let 
the sender know immediately if you have received this by mistake and delete it 
immediately. 

-- 
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