CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

EventAggregator with MEF

1089 Views
Copy Code Show/Hide Line Numbers
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();        
        }
    }
}
by Glenn Block
  January 10, 2010 @ 11:30pm
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.

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate