I am experimenting with using NHibernate events to track/audit changes
on my domain model using the AR EventListener attributes, but I am
running into a problems setting them up.

I am using a recent nightly (1261) of the castle stack on a local dev
environment (win xp) against a sqlite db.

I have created several listener classes to do some testing (see
listing below) with the different ways to wire up the listeners.

The two ways that I have successfully got an event to fire
OnPostUpdate was to use just the [EventListener] attribute or the
[assembly: AddEventListener(typeof(GlobalByAssemblyEventListener))]
attribute.  This is not ideal for my situation because I would like to
create EventListeners that specifically watch only one or a small
number of similar domain objects which all inherit a common base class
or implement an interface.  So, I tried to configure the
EventListeners with the Include argument, but I have been unsuccessful
at getting an EventListener to only fire for one specific type.  I
tried to use [EventListener(Include = new [] { typeof(Project) })] or
[assembly: AddEventListener(typeof(ProjectByAssemblyEventListener),
Include = new[] { typeof(Project) })] but neither events fired (or the
methods were never called).

Any help, ideas, suggestions would be appreciated to allow me to
configure an EventListener for one or more domain objects.

Finally, my end solution is to be able to use the container
integration as specified in the spec, "All components added to the
container that specify an NHibernate event listener interface as
service will be added for that specific event."  However, I want to
answer this question before moving on to other scenarios.

Thanks,
Jason

PS  Here is the complete listing of all my attempts at configuration.

[assembly: AddEventListener(typeof(GlobalByAssemblyEventListener))]
[assembly: AddEventListener(typeof(ProjectByAssemblyEventListener),
Include = new[] { typeof(Project) })]

namespace Foo
{
    [EventListener]
    public class GlobalEventListener : IPostUpdateEventListener
    {
        public void OnPostUpdate(PostUpdateEvent @event)
        {
            var project = @event.Entity as Project;

            new ProjectComment { Note = "GlobalEventListener", Project
= project, Owner = project.Owner.Name }.Save();
        }
    }

    [EventListener(Include = new [] { typeof(Project) })]
    public class ProjectEventListener : IPostUpdateEventListener
    {
        public void OnPostUpdate(PostUpdateEvent @event)
        {
            var project = @event.Entity as Project;

            new ProjectComment { Note = "ProjectEventListener",
Project = project, Owner = project.Owner.Name }.Save();
        }
    }

    public class GlobalByAssemblyEventListener : IPostUpdateEventListener
    {
        public void OnPostUpdate(PostUpdateEvent @event)
        {
            var project = @event.Entity as Project;

            new ProjectComment { Note =
"GlobalByAssemblyEventListener", Project = project, Owner =
project.Owner.Name }.Save();
        }
    }

    public class ProjectByAssemblyEventListener : IPostUpdateEventListener
    {
        public void OnPostUpdate(PostUpdateEvent @event)
        {
            var project = @event.Entity as Project;

            new ProjectComment { Note =
"ProjectByAssemblyEventListener", Project = project, Owner =
project.Owner.Name }.Save();
        }
    }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to castle-project-users@googlegroups.com
To unsubscribe from this group, send email to 
castle-project-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to