Extensions without attributes

Nov 23, 2009 at 6:18 PM

I have a question about adding extensions to Unity without those extensions relying on attribute decorated classes.

In particular I have followed through the code for the original extension example in the quick starts for the Event Broker.

I see where this extension picks up the meta data it needs from the Publishes/SubscribesTo attributes.

What I would like to explorer is how to achieve a similar extension where the meta data about the event sources and destinations can be provided via the code which sets up the container.

Something like this made up example:

 

         IUnityContainer container = new UnityContainer()
                .AddNewExtension<SimpleEventBrokerExtension>(),
                .RegisterType<ILogger, TraceLogger>(),
.RegisterType<IStoplightTimer, RealTimeTimer>(),
.RegisterType<IMyPublisher, new EventSource("LogicalEventName", eventMethodName)>(),
 .RegisterType<IMySubscriber new EventSink("LogicalEventName", sinkMethodName)>() ;

Or perhaps:

         IUnityContainer container = new UnityContainer()
.AddNewExtension<SimpleEventBrokerExtension>(),
.RegisterType<ILogger, TraceLogger>(),
.RegisterType<IStoplightTimer, RealTimeTimer>(),
.RegisterEventSourceIMyPublisher, new EventSource("LogicalEventName", eventMethodName)>(),
 .RegisterEventSink<IMySubscriber new EventSink("LogicalEventName", sinkMethodName)>() ;

 

Then whenever a new IMyPublisher instance is created it will have its eventMethodName wired to any existing IMySubscriber instance sinkMethodName.

So at the end of they day it isn't any different from the example in the quick start except that it can be used on classes which are not attribute decorated.

Can anyone point me at an example of such a approach.

Thanks

Nov 24, 2009 at 4:17 AM

Ok so I have mostly worked through this by adding to the EventBroker extension to add more configuration abilities.

While I have this working, it was a bit more of a dark art than I'd prefer.  I would very much like to read some details on the "policy" and "strategy" concepts.

It looks like this content was lost when Unity shifted from MSDN to Codeplex....or at least I'm missing it.

The CHM help file section "Creating Container Extensions" is gutted and says to go to the Unity site here on Codeplex for the details.

Can someone point me to the details on this?

 

Thanks

 

Dec 17, 2009 at 10:34 PM

Jeff,

This documentation is currently unavailable. It's been our intention to produce Unity extension documentation. Unfortunately, that work has not been completed due to other higher priorities.

Our team will be working on producing it for Unity 2.0.

By the way, Unity has never shifted from MSDN to Codeplex. Both channels are active. MSDN is where released versions are hosted and Codeplex is where the new version we are currently working on is hosted as well as the forum and issue tracker.

Grigori