Markus...thanks for the clarification.  It appears that I need to read
more on nhibernate events.

On to my next question, in the spec, it mentions "All components added
to the container that specify an NHibernate event listener interface
as service will be added for that specific event.", so I added this
during the initialization of my container

AddComponent("global.eventlistener", typeof(IPostUpdateEventListener),
typeof(IoCEventListener));

and my IoCEventListener is

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

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


But, OnPostUpdate is never called.  Again, is there something I am not
understanding or doing incorrectly?

Thanks,
Jason

On Wed, Jul 29, 2009 at 1:54 PM, Markus Zywitza<[email protected]> wrote:
> Sorry, but you can't do this. Listeners cannot be registered per persistent
> types, only per session factory. AR uses base types to differ types that go
> into different session factories, therefore you can narrow the event
> listener registration per type.
>
> You have two choices:
> Check in you listener whether one of the types you are interested in was
> updated or
> Put the types in a separate session factory by creating separate
> <config>-nodes in your configuration, but this means you cannot cascade to
> and with types in your main configs.
> -Markus
> 2009/7/29 jsmorris <[email protected]>
>>
>> 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to