Further playing around...
I was thinking maybe the option is similar to ninject per call scope
private IHandler ScopeRootBinder(IHandler[] handlers)
{
return handlers.FirstOrDefault();
}
Will the first one always be the parent component being resolved ?
On Wednesday, 12 December 2012 14:51:21 UTC+2, nst wrote:
>
> No suggestions ?
>
> On Wednesday, 5 December 2012 19:08:21 UTC+2, nst wrote:
>>
>> I have been playing around with BoundTo and thinking that may be a better
>> option....
>>
>> Here is an example
>>
>> IWindsorContainer container = new WindsorContainer();
>>
>> container.Register(Component.For<Container>().ImplementedBy<Container>().LifestyleTransient().OnDestroy(x
>> => x.Desroyed = true),
>>
>> Component.For<A>().ImplementedBy<A>().LifeStyle.Transient.OnDestroy(x =>
>> x.Desroyed = true),
>>
>> Component.For<B>().ImplementedBy<B>().LifeStyle.Transient.OnDestroy(x =>
>> x.Desroyed = true),
>>
>> Component.For<C>().ImplementedBy<C>().LifestyleTransient().OnDestroy(x =>
>> x.Desroyed = true),
>>
>> Component.For<AB>().ImplementedBy<AB>().LifeStyle.BoundTo<Container>().OnDestroy(x
>> => x.Desroyed = true));
>>
>>
>> ObjectResolver.Initialise(container);
>>
>> var c = ObjectResolver.Resolve<Container>();
>>
>> Assert.AreSame(c.A.AB, c.B.AB);
>>
>> var s = ObjectResolver.Resolve<Container>();
>>
>> Assert.AreSame(s.A.AB, s.B.AB);
>> Assert.AreNotSame(s.A.AB, c.A.AB);
>>
>> var a = ObjectResolver.Resolve<A>();
>> Assert.AreNotSame(a.AB, s.A.AB); ---- This fails.... any way
>> around this ?
>>
>>
>> Where A and B are repositories and AB is the unitofwork and container is the
>> Form... based on the test it looks like that works. The only problem is if I
>> want to resolve a unit of work outside of a form's context. I suspect there
>> isnt a way for a lifestyle to revert to a transient lifestyle if the boundto
>> fails ?
>>
>>
>> Would appreciate any thoughts on this... is BoundTo a better approach ?
>>
>>
>> On Wednesday, 5 December 2012 13:18:32 UTC+2, nst wrote:
>>>
>>> I want to use the scoped life styles in winforms in conjunction to the
>>> Repository & Unit Of Work implementations with Nhibernate.
>>> i.e get windsor to new up the form and inject the defined repositories
>>> and have them all share the same unit of work.
>>>
>>> My thinking was that I can call the begin scope prior to new'ing the
>>> form and store the IDisposable and release when the form is closed. Then
>>> when each form is opened a new Begin Scope is called.
>>>
>>> Does this sound viable ? There is a problem though - if form 1 is opened
>>> and then form 2 is opened the latest begin scope would be owned by form 2.
>>> If the resolve method was called from form 1 (say button click) then the
>>> UoW would be associated with Form 2's scope ... this correct ?
>>>
>>> Are there any suggestions how I can achieve what I am trying to do ?
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/castle-project-users/-/Z79gOmEi-IoJ.
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.