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]>
.
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].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.