Apr 15, 2012 at 8:13 AM
Edited Apr 15, 2012 at 8: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 http://www.global-webnet.net/blogengine/post/2008/08/02/Composite-WPF-Implementing-the-Unity-Event-Broker-in-a-CompositeWPF-application.aspx)
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?
|
|
Editor
Apr 15, 2012 at 3: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
entlib.support@live.com
|
|
Apr 16, 2012 at 6:24 AM
Edited Apr 16, 2012 at 6: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.
|
|
|
|
Thanks for helping me.
|
|