Service Layer : WCF services
In this case, the idea explained earlier can be done with a custom implementation of IServiceBehavior that will attach to endpoint an IDispatchMessageInspector. There you'll be able to open a session & transaction (look also at UnitOfWork pattern) before making the call to service and close session & commit transaction after the service call. It's just one of the options... On Thu, Aug 5, 2010 at 12:28 PM, Luka <[email protected]> wrote: > Oh, and I forgot to tell that this is not a web application. It is an > application composed of those layers: > UI: silverlight > Service Layer : WCF services > Domain Layer > Data access layer > and I am using repositories in the service layer. > > On Aug 5, 11: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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- 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.
