Language: C#
EventAggregator with MEF
using System.ComponentModel.Composition; using Microsoft.Practices.Composite.Events; //this version uses a static backing field so that the instance is automatically shared across all containers. public class EventAggregatorPart { private static IEventAggregator _eventAggregator; static EventAggregatorPart() { _eventAggregator=new EventAggregator(); } [Export] public IEventAggregator EventAggregator { get { return _eventAggregator; } } } //this version does not share the instance across containers. public class EventAggregatorPart { [Export] public IEventAggregator EventAggregator { get { return new EventAggregator(); } } }
Tags:
Description:
Dropping this part into your catalog allows you to import EventAggregator in MEF without requiring any host configuration on the container.
The first part uses a private static reference thus allow parts across containers to communicate although they are not in a hierarchy.
The second part is shared only within a container scope.
The first part uses a private static reference thus allow parts across containers to communicate although they are not in a hierarchy.
The second part is shared only within a container scope.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

