We also have a Silverlight/WCF application with NHibernate.  However,
we've adopted the Unit of Work pattern and modeled it after Jimmy
Nilsson's workspace concept.

Our WCF service is a thin facade in front of our application
services.  The application services are responsible for:

1. Orchestrating between domain services and domain aggregate roots
2. Converting between DTOs we use through WCF and domain value objects
3. Defining the unit of work

Thus, our domain services and repositories expect their to already be
a unit of work (which in our case wraps an NHibernate session).  The
domain is ont responsible for opening nor closing it but just expects
it to be already set up.  It is our application layer that manages the
unit of work boundary (a.k.a. NHibernate session management).

This has been working quite well!



On Aug 5, 5:16 am, Luka <[email protected]> wrote:
> Hi,
> I have a project where i am using repositories to access my data with
> nhibernate.
> So I have an IRepository<TDomain, TKey> interface and its
> implementation.
> This repository is from CodeSmith template and it has incapsulated
> session management from that template.
> Now when I want to use it I do:
>
> public Person GetPersonById(int id)
> {
>    Person person = null;
>    using (var rep = ObjectFactory.GetInstance<IRepository<Person,
> int>>())
>    {
>        person = rep.GetById(1);
>    }
>    return person;
>
> }
>
> now I have the person object but the problem is this:
> the Person class has a collection of Addresses that is lazy
> initialized.
> So when in the code I do:
>
> Person person = GetPersonById(1);
> foreach(var address in person.Addresses)
> {...}
>
> I get lazy initialization exception because there is no more session
> open.
>
> What must I do,  how must I use this repository so I wont get lazy
> exceptions?

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