Thanks for the reply. I think the issue was with the setup of my unit test. I was grabbing the reference to the IAuthroizationRepository in the SetUp of my unit test from my Windsor container. This was grabbing a child ISession from the container (the container was configured to return a child session whenever ISession was requested). I was then setting up security permissions on this child session. Then when my actual test method ran, the NH Event listener was also getting the reference for IAuthorizationRepository from the windsor container, but this was returning the same child session used in my unit test setup, which I think is why the AuthRepository never committed anything to the DB within the EventListener.
I changed the configuration of the container to NOT return a child session of the current session whenever ISession is resolved. I explicity get the child session within my NH EventListener by resolving ISession and calling ISession.GetSession(EntityMode.Poco). I then instantiate the AuthorizationRepository manually and pass it the child session. I would have liked to have gotten the reference to the AuthorizationRepsoitory from within my listener through the windsor container, but I couldn't figure out a way to pass a child ISession to its Ctor without configuring the container to return a child session when ISession is resolved (which led to the problem described above). Things seem to be working now. On Apr 4, 1:48 am, Ayende Rahien <[email protected]> wrote: > You probably need to call Flush on the child session. > > > > On Thu, Apr 1, 2010 at 5:58 PM, Jim Wheaton <[email protected]> wrote: > > Hi all, > > > I’m using Rhino Security in my project. I would like to use > > NHibernate event listeners that implement IPostInsertEventListener and > > IPostUpdateEventListener to associate entities with an EntityGroup. > > > For example, if a Patient object has a reference to a Hospital object, > > then I’d like to associate the patient entity with the hospital > > EntityGroup when the NH event listener executes. > > > In the event listener, I am getting a reference to the > > IAuthorizationRepository through my WindsorContainer. The container > > also registers ISession, which is a factory method that returns a > > child session of the current session. That way, the > > IAuthorizationRepository is configured with the child session. I can > > call methods such as > > IAuthorizationRepository.GetEntityGroupsByName(groupName) within the > > event listener and they return the correct data. However, when I try > > to call IAuthorizationRepository.AssociateEntityWith(patient, > > groupName), nothing happens. > > > I am using NHProfiler to debug and I don’t see any inserts being > > called. I’ve also stepped through the RhinoSecurity code from this > > call and it seems to work fine, but no insert is being issued to the > > DB. > > > I know I am doing something wrong, but cannot figure out what. Is > > using the IAuthorizationRepository within an NHEventListener an > > appropriate design choice. If so, do you know where I’m going wrong? > > > Here is the event listener: > > > public class EncounterSaveOrUpdateEventListener : > > IPostInsertEventListener > > { > > > public void OnPostInsert(PostInsertEvent @event) > > { > > var patient = @event.Entity as Patient; > > if (patient != null) > > { > > > //the windsor container is configured to return a > > child session when ISession is requested from the container > > var authRepository = > > SafeServiceLocator<IAuthorizationRepository>.GetService(); > > > //I’ve simplified the code for this email. The real > > code contains additional checks > > > if(_authRepository.GetEntitiesGroupByName(patient.Hosptial.Name) != > > null) > > _authRepository.AssociateEntityWith(patient, > > patient.Hosptial.Name); > > } > > } > > } > > > Any help is appreciated > > > Cheers, > > > Jim Wheaton > > > -- > > You received this message because you are subscribed to the Google Groups > > "Rhino Tools Dev" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<rhino-tools-dev%2Bunsubscribe@ > > googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rhino-tools-dev?hl=en. -- You received this message because you are subscribed to the Google Groups "Rhino Tools Dev" 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/rhino-tools-dev?hl=en.
