thx a lot,
it looks like a gr8 sample

On Tue, Oct 5, 2010 at 9:29 PM, Jason Meckley <[email protected]>wrote:

> I'm going to post the full example on Google Code in the next 24
> hours.
>
> On Oct 5, 2:24 pm, Roei Bar <[email protected]> wrote:
> > could you guys show how to use this sample?
> >
> > 2010/10/5 Jason Meckley <[email protected]>
>  >
> > > short and sweat!
> >
> > > public class EventBrokerContributor :
> > > IContributeComponentModelConstruction
> > > {
> > >        public void ProcessModel(IKernel kernel, ComponentModel model)
> > >        {
> > >                if (model.ImplementationIsAListener() == false) return;
> >
> > >                var steps = model.LifecycleSteps;
> > >                var broker = kernel.Resolve<IEventRegister>();
> > >                steps.Add(LifecycleStepType.Commission, new
> > > RegisterWithEventBroker(broker));
> > >                steps.Add(LifecycleStepType.Decommission, new
> > > UnregisterWithEventBroker(broker));
> > >        }
> > > }
> >
> > > public class RegisterWithEventBroker : ILifecycleConcern
> > > {
> > >        private readonly IEventRegister broker;
> >
> > >        public RegisterWithEventBroker(IEventRegister broker)
> > >        {
> > >                this.broker = broker;
> > >        }
> >
> > >        public void Apply(ComponentModel model, object component)
> > >        {
> > >                broker.Register(component);
> > >        }
> > > }
> >
> > > public class UnregisterWithEventBroker : ILifecycleConcern
> > > {
> > >        private readonly IEventRegister broker;
> >
> > >        public UnregisterWithEventBroker(IEventRegister broker)
> > >        {
> > >                this.broker = broker;
> > >        }
> >
> > >        public void Apply(ComponentModel model, object component)
> > >        {
> > >                broker.Unregister(component);
> > >        }
> > > }
> >
> > > On Oct 5, 8:15 am, Krzysztof Koźmic <[email protected]>
> > >  wrote:
> > > >   No worries. Actually I was thinking - this might serve as a good
> basis
> > > > for a sample app showing Windsor's extensibility. Would you be
> > > > interested in putting together a small sample app built on top of
> that
> > > > facility and submitting it as a sample for Windsor?
> >
> > > > Pretty much like the other sample we have for Silverlight:
> > >http://github.com/HEskandari/Castle-Windsor-Examples
> >
> > > > cheers,
> > > > Krzysztof
> >
> > > > On 5/10/2010 10:05 PM, Jason Meckley wrote:
> >
> > > > > thank you. I'll research that this morning.
> >
> > > > > On Oct 4, 6:24 pm, Krzysztof Koźmic<[email protected]>
> > > > > wrote:
> > > > >> Looks good although custom Activator swapped under the covers
> feels
> > > too
> > > > >> intrusive. I'd use lifestyle concerns instead.
> >
> > > > >> sent from my HTC Desire
> >
> > > > >> On 05/10/2010 6:07 AM, "Jason Meckley"<[email protected]>
> > >  wrote:
> >
> > > > >> I'm spiking a sample of an event broker where listeners are
> > > > >> (un)registered to the broker during resolution/destruction. the
> code
> > > > >> below appears to be working, but I wanted to double check with the
> > > > >> community to make sure I'm not missing something obvious (or not
> so
> > > > >> obvious).
> >
> > > > >> public class EventBrokerFacility
> > > > >>         : AbstractFacility
> > > > >> {
> > > > >>         protected override void Init()
> > > > >>         {
> > > > >>                 Kernel.ComponentModelBuilder.AddContributor(new
> > > > >> EventBrokerContributor());
> > > > >>                 Kernel.Register(Component
> >
> > > > >>   .For<SynchronizationContext>()
> >
> > > > >>   .ImplementedBy<WindowsFormsSynchronizationContext>()
> >
> > > .LifeStyle.Singleton,
> > > > >>                                                 Component
> >
> > > .For<IEventPublisher,
> > > > >> IEventRegister>()
> >
> > > > >>   .ImplementedBy<EventBroker>()
> >
> > > > >>   .LifeStyle.Singleton);
> > > > >>         }}
> >
> > > > >> public class EventBrokerContributor
> > > > >>         : IContributeComponentModelConstruction
> > > > >> {
> > > > >>         private readonly Type activator = typeof
> > > > >> (EventBrokerComponentActivator);
> > > > >>         private readonly Type listener = typeof (IListener<>);
> >
> > > > >>         public void ProcessModel(IKernel kernel, ComponentModel
> model)
> > > > >>         {
> > > > >>                 var isAListener = model
> > > > >>                         .Implementation
> > > > >>                         .GetInterfaces()
> > > > >>                         .Where(i =>  i.IsGenericType)
> > > > >>                         .Select(i =>
>  i.GetGenericTypeDefinition())
> > > > >>                         .Any(i =>  i == listener);
> >
> > > > >>                 if (isAListener == false) return;
> > > > >>                 model.CustomComponentActivator = activator;
> > > > >>         }}
> >
> > > > >> public class EventBrokerComponentActivator
> > > > >>         : DefaultComponentActivator
> > > > >> {
> > > > >>         private IEventRegister Broker
> > > > >>         {
> > > > >>                 get { return Kernel.Resolve<IEventRegister>(); }
> > > > >>         }
> >
> > > > >>         public EventBrokerComponentActivator(
> > > > >>                 ComponentModel model,
> > > > >>                 IKernel kernel,
> > > > >>                 ComponentInstanceDelegate onCreation,
> > > > >>                 ComponentInstanceDelegate onDestruction)
> > > > >>                 : base(model, kernel, onCreation, onDestruction)
> > > > >>         {
> > > > >>         }
> >
> > > > >>         public override object Create(CreationContext context)
> > > > >>         {
> > > > >>                 var component = base.Create(context);
> > > > >>                 Broker.Register(component);
> > > > >>                 return component;
> > > > >>         }
> >
> > > > >>         public override void Destroy(object instance)
> > > > >>         {
> > > > >>                 Broker.Unregister(instance);
> > > > >>                 base.Destroy(instance);
> > > > >>         }
> >
> > > > >> }
> >
> > > > >> as an example this class will use the
> EventBrokerComponentActivator
> > > > >> class Presenter : IListener<Foo>,IListener<Bar>
> > > > >> {
> >
> > > > >> }
> >
> > > > >> while this class uses the default.
> > > > >> class Service
> > > > >> {
> >
> > > > >> }
> >
> > > > >> --
> > > > >> 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]<castle-project-users%[email protected]>
> <castle-project-users%[email protected]<castle-project-users%[email protected]>
> >
> > > <castle-project-users%[email protected]<castle-project-users%[email protected]>
> <castle-project-users%[email protected]<castle-project-users%[email protected]>
> >
> >
> > > > >> .
> > > > >> For more options, visit this group athttp://
> > > groups.google.com/group/castle-project-users?hl=en.
> >
> > > --
> > > 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]<castle-project-users%[email protected]>
> <castle-project-users%[email protected]<castle-project-users%[email protected]>
> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/castle-project-users?hl=en.
> >
> >
>
> --
>  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]<castle-project-users%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
>
>

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