Hi 

 

I want to run some additional code AFTER a successful save (insert) to a
couple of entities after a successful commit. I use a session per request
strategy which is wrapped up as  UOW.

I have Googled around a bit and have come up with the following idea.

 

1.       OnSave add the saved entities to a temporary list

2.       PostFlush enumerate through the saved list and run the extra code.

 

My question is, is this a sound premise? Are there any gotcha's that won't
run the code in some circumstances? If so is there a workaround.

 

I am also wanting to perform the same using onDelete and FindDirty for
updates. 

 

     public class AppInterceptor : EmptyInterceptor

     {

           private readonly IList<object> insertItems = new List<object>();

 

           public override bool OnSave(object entity, object id, object[]
state, string[] propertyNames, IType[] types)

           {

                var campaign = entity as Campaign;

                if (campaign != null)

                     insertItems.Add(campaign);

 

                var contact = entity as Contact;

                if (contact != null)

                     insertItems.Add(contact);

 

                return base.OnSave(entity, id, state, propertyNames, types);

           }

 

           public override void PostFlush(ICollection entities)

           {

                base.PostFlush(entities);

 

                foreach (var entity in insertItems)

                {

                     var campaign = entity as Campaign;

                     if (campaign != null)

                           new LuceneCampaign().Index(campaign);

 

                     var contact = entity as Contact;

                     if (contact != null)

                           new LuceneContact().Index(contact);

 

                }

           }

 

     }

 

I am steering away from the repository pattern so Session.Save could be
called anywhere in my code.

Many Thanks
Rippo

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