Hm, I used the current movement in this area to convert my IInterceptor int
an ILoadEventListener.

My IInterceptor was also injected a service, and even though it is advised
against in the docs, I inject my service ito the event listener as well (the
service and the interceptor/loadevent form a conceptual unit). Do you think
this is a bad practice, if so, how could I circumvent this?

public class DiscountLoadListener : IDomainLoadEventListener //
markerinterface
    {
        private readonly IDiscountProviderService service;
        private readonly ILogger logger = new NullLogger();

        public DiscountLoadListener(IDiscountProviderService service,
ILogger logger)
        {
            if (service == null) throw new ArgumentNullException("service");
            this.service = service;
            this.logger = logger;
        }

        public void OnLoad(LoadEvent theEvent, LoadType loadType)
        {
            var entity = theEvent.InstanceToLoad as IDiscountable;
            if (entity == null) return;
            var provider = service.GetDiscountProvider(entity);
            if (provider == null) return;
            entity.SetDiscount(provider);
            logger.Debug(string.Format("Article {0} with key {1} received a
discount.", entity.Name, entity.Key));
        }


> On Wed, Mar 11, 2009 at 10:43 PM, Tuna Toksoz <[email protected]> wrote:
> hmmm
>
> ok, use IConfigurationContributor.
>
>
> http://tunatoksoz.com/post/NHibernate-Integration-Facility-IConfigurationContributor.aspx
>
> And modify the configuration with your very own interceptor.
>


I would like to append these listeners using the IConfigurationContributor,
but I don´t know how to tell my factory or facility about them. Do you have
an example...?

public class DomainConfigurationContributor : IConfigurationContributor
    {
        private readonly IList<ILoadEventListener> loadListeners;

        public DomainConfigurationContributor(IKernel kernel)
        {
            loadListeners = new
List<ILoadEventListener>(kernel.ResolveAll<IDomainLoadEventListener>())

                                {new DefaultLoadEventListener()};
        }

        /// <summary>
        ///             Modifies available <see
cref="T:NHibernate.Cfg.Configuration" /> instances.

        /// </summary>
        /// <param name="name">Name of the session factory</param>
        /// <param name="config">The config for sessionFactory</param>

        public void Process(string name, Configuration config)
        {
            config.EventListeners.LoadEventListeners = loadListeners.ToArray();

        }
    }

    public interface IDomainLoadEventListener : ILoadEventListener { }


2009/3/11 Tuna Toksoz <[email protected]>

> I need to improve the documentation, the most unfunny part :)
>

I know, but if you think I could help with it (formatting, cooking up an
example, etc...), go ahead and tell me :) - Problem is, my domain knowledge
is ... well you know how it is. Just want to show my gratitude.

-- 
Jan

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