What you are calling "Context" is similar to CpBT, probably, one difference
is that the implementation on uNhAddIns is not so wired with one specific
IoC (it is more AOP than IoC oriented).

2009/3/24 Germán Schuager <[email protected]>

> Hi Fabio,I've implemented a similar concept (without the child containers)
> using Castle:
> http://blog.schuager.com/2009/03/rich-client-nhibernate-session.html I'd
> like to know what you think about it.
>
> Regards.
>
> On Tue, Mar 24, 2009 at 6:27 PM, Fabio Maulo <[email protected]> wrote:
>
>> No problem, but a real functional example would be better for NH's users,
>> believe me.
>>
>> 2009/3/24 Peter Morris <[email protected]>
>>
>>>
>>> Hi Fabio
>>>
>>> > Interesting.Do you have a public example ?
>>>
>>> I'm a complete newbie with NH so no :-)
>>>
>>> The implementation though would be something like
>>>
>>> var mainContainer = new UnityContainer();
>>>
>>> //Registration of new feature
>>> mainContainer.AddNewExtension<HierarchicalLifetimeExtension>();
>>>
>>> //Register repositories etc from some config, but here manually for
>>> illustration purposes
>>> mainContainer.RegisterType<ISomeBusinessProcess, SomeBusinessProcess>(new
>>> HierarchicalLifetimeManager());
>>>
>>>
>>>
>>> Now let's say the constructor of ISomeBusinessProcess requires an
>>> IUnitOfWork, which is our context.  You would do this
>>>
>>> //01: Create a child container to hold the context
>>> using (var childContainer = mainContainer.CreateChildContainer())
>>> {
>>>
>>>    //02: Register the context in the child container
>>>    childContainer.RegisterInstance<IUnitOfWork>(new UnitOfWork());
>>>
>>>    //03: Resolve the business process in the child container.
>>>    //This creates it and injects the IUnitOfWork we just created
>>>    var someBusinessProcess =
>>> childContainer.Resolve<ISomeBusinessProcess>();
>>>    someBusinessProcess.Execute();
>>> }
>>>
>>> Obviously this is a procedural example, the real thing wouldn't reference
>>> the containers directly etc.  But the point is that anything the
>>> SomeBusinessProcess requires will be injected and will also work with the
>>> same IUnitOfWork instance because it is all operating within the same
>>> child
>>> container.
>>>
>>>
>>> Pete
>>>
>>>
>>>
>>>
>>
>>
>> --
>> Fabio Maulo
>>
>>
>>
>
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to