How to replace missing IBuilderContext.Locator

Apr 15, 2012 at 9:13 AM
Edited Apr 15, 2012 at 9:16 AM

Hello, in Unity examples and extensions is commonly used IBuilderContext.Locator. But in Unity 2.0 this property disappears. I have read that Locator should be replaced by using policy, but I am stucked in next situation (snippet is from descendant of BuilderStrategy from


EventBroker broker = context.Locator.Get<EventBroker>(typeof(EventBroker));


How can be locator replaced by policy in this piece of code, which is commonly used in Unity extensions? Should I store container in policy and use container as resolver? Or there is better way?

Apr 15, 2012 at 4:48 PM

Are you specifically concerned about the EventBroker?  The Unity Documentation MSI provides a Unity 2 EventBroker implementation.  This could help you.

If you examine the source the EventBroker is created and the instance registered in the container.  Then in the EventBrokerWireupStrategy the EventBroker is retrieved using the NewBuildUp method:

var broker = context.NewBuildUp<EventBroker>();

Randy Levy
Enterprise Library support engineer 

Apr 16, 2012 at 7:24 AM
Edited Apr 16, 2012 at 7:47 AM

Unity 2.0's IBuilderContext has the NewBuildUp<T>()-method which allows you to do someting similar to Locator.Get<T>(). You can use that in much the same way I think.

I would recommend you don't use the EventBroker described in the Unity samples. Have a look this implementation of the EventAggregator pattern instead.

Apr 16, 2012 at 7:13 PM

Thanks for helping me.