New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of MEF
C#
private IEnumerable<MemberInfo> GetImportMembers(Type type)
        {
            var local = new HashSet<string>();
            if (type.IsAbstract)
            {
                yield break;
            }
 
            foreach (var member in GetDeclaredOnlyImportMembers(type))
            {
35 Views
no comments
 
C#
namespace Entity
{
public interface IBase
{
    string Name { get; }    
}
 
[Export("Base2", typeof(IBase))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class Base2 : IBase
by codding4fun   June 08, 2010 @ 1:55am
38 Views
no comments
 
C#
//this is the MEF Team Code
namespace System.ComponentModel.Composition.AttributedModel
{
    internal class AttributedPartCreationInfo : IReflectionPartCreationInfo
    {
private IEnumerable<MemberInfo> GetImportMembers(Type type)
{
    if (type.IsAbstract)
    {
        yield break;
by codding4fun   June 08, 2010 @ 1:32am
34 Views
no comments
 
C#
 
by codding4fun   June 08, 2010 @ 1:27am
21 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;
 
namespace MEFFactory
{
    public interface IMessage
    {
by JamesEggers   April 20, 2010 @ 2:45pm
Tags: MEF
83 Views
no comments
 
C#
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;
 
namespace HelloMEF
{
    public interface IGreetings
    {
        void Hello();
by Andy Sherwood   April 20, 2010 @ 11:32am
Tags: MEF
47 Views
no comments
 
C#
namespace Nowcom.Quicksilver
{
  public interface IMessage
  {
  }
}
 
namespace Nowcom.Quicksilver
{
    using System.ComponentModel.Composition;
186 Views
no comments
 
C#
public class LookupExportProvider<T> : ExportProvider
{
    private ILookup<string, T> _lookup;
 
    public LookupExportProvider(ILookup<string, T> lookup)
    {
        if (lookup == null) throw new ArgumentNullException("lookup");
 
        _lookup = lookup;
    }
by obiwanjacobi   April 12, 2010 @ 1:48am
Tags: MEF
98 Views
2 comments
 
C#
public class DictionaryCatalog<T> : ComposablePartCatalog
{
    public DictionaryCatalog(IDictionary<string, T> dict)
    {
        InitializeParts(dict);
    }
 
    private void InitializeParts(IDictionary<string, T> dict)
    {
        var partDefinitions = new List<ComposablePartDefinition>();
by obiwanjacobi   April 11, 2010 @ 11:30pm
Tags: MEF
71 Views
no comments
 
C#
namespace Nowcom.Quicksilver
{
    using System.ComponentModel.Composition.Primitives;
    using System.Linq;
    using System;
    using System.ComponentModel.Composition.ReflectionModel;
    using System.Collections.Generic;
 
    public class WrappedPartDefinition: ComposablePartDefinition
    {
by Robert Kozak   April 08, 2010 @ 6:04pm
60 Views
no comments
 
C#
namespace Nowcom.Quicksilver
{
    using System;
    using System.Reflection;
    using System.Windows;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
 
    [Export]
    public class ViewContainer 
by Robert Kozak   April 07, 2010 @ 4:25pm
158 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
 
namespace DynamicObjectContracts
{
    public class Program
by Glenn Block   March 17, 2010 @ 9:32am
Tags: Dynamic, MEF
308 Views
no comments
 
C#
public interface IRuleMetadata
{
    [DefaultValue(0)]
    int ExecutionOrder { get; }
}
 
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class RuleAttribute : ExportAttribute, IRuleMetadata
{
    public RuleAttribute(int executionOrder)
by TheCodeJunkie   February 13, 2010 @ 3:30pm
Tags: MEF
168 Views
no comments
 
C#
public class LoggerRegistry : PartRegistry
{
    public LoggerRegistry()
    {
        Part<PartConvention>()
            .ForTypesMatching(x => x.GetInterfaces().Contains(typeof(ILogger)))
            .Exports(x => x.Export<ExportConvention>()
                .ContractType<ILogger>()
                .ContractName<ILogger>()
                .Members(m => new[] { m }))
by TheCodeJunkie   February 08, 2010 @ 2:38pm
Tags: MEF
71 Views
no comments
 
C#
public class ConventionPart<T> : IPartImportsSatisfiedNotification
{
    /// <summary>
    /// Initializes a new instance of the <see cref="ConventionPart{T}"/> class.
    /// </summary>
    public ConventionPart()
    {
    }
 
    [ImportMany]
by TheCodeJunkie   February 07, 2010 @ 3:14pm
Tags: MEF
94 Views
no comments
 
C#
public class ViewModelInitializer<TViewModel,TModel> where TViewModel : IViewModel<TModel>
{
    private Func<TViewModel> _viewModelFactory;
 
    public ViewModelInitializer(Func<TViewModel> viewModelFactory)
    {
        _viewModelFactory = viewModelFactory;
    }
 
    public void Initialize(FrameworkElement view, TModel model)
by Glenn Block   February 07, 2010 @ 3:07pm
Tags: MEF
280 Views
no comments
 
C#
public class ConfigurationExportProvider : ExportProvider
{
    protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
    {
        if (ConfigurationManager.AppSettings.AllKeys.Contains(definition.ContractName))
        {
            var value = ConfigurationManager.AppSettings[definition.ContractName];
            yield return new Export(definition.ContractName, () => value);
        }
        else
February 06, 2010 @ 10:12am
77 Views
no comments
 
C#
class Program
{
    static void Main(string[] args)
    {
        var instance = new Program();
        var cat = new AssemblyCatalog(typeof(Program).Assembly);
        var container = new CompositionContainer(cat);
        container.ComposeParts(instance);
 
        foreach (var plug in instance.Plugins)
by bnaya   January 29, 2010 @ 4:10am
246 Views
no comments
 
C#
// Below RecentlyUsedTrackerConfiguration provides configuration information through property exports. MEF pulls on the property getters and exports that info. 
// If the part needs to be data drvien, you can still access a service behind the scenes in the getter (or the constructor) to get the info.
 
public class RecentlyUsedTrackerConfiguration
{
  public RecentlyUsedTrackerConfiguration()
  {
     //set values here
  }
by Glenn Block   January 26, 2010 @ 6:34pm
Tags: MEF
257 Views
no comments
 
C#
class Program
{
    private static ImpCls s_imp = new ImpCls();
    private static string[] s_beforeState;
 
    static void Main(string[] args)
    {
        var c = new TypeCatalog(typeof(ExpMtd1));
        var catalog = new AggregateCatalog(c);
        var container = new CompositionContainer(catalog);
by bnaya   January 15, 2010 @ 1:17am
92 Views
no comments
 
C#
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()
    {   
by Glenn Block   January 10, 2010 @ 11:30pm
396 Views
no comments
 
C#
namespace Nowcom.Quicksilver.GoogleAnalytics
{
    public class Test
    {
        [AnalyticsCategories("TEST")]
        public readonly string TestEvent = "TestEvent";
    }
 
    public interface IAnalyticsCategoriesMetadata
    {
by Robert Kozak   January 10, 2010 @ 2:49pm
171 Views
no comments
 
C#
 
var catalog = new DirectoryCatalog(@".\");
var rootCatalog = new FilteredCatalog(catalog, cpd=>!cpd.Metadata.ContainsKey("Scope") || (cpd.Metadata.ContainsKey("Scope") && cpd.Metadata["Scope"].Equals("Root"));
var childCatalog = new FilteredCatalog(catalog, cpd=>cpd.Metadata.ContainsKey("Scope") && cpd.Metadata["Scope"].Equals("Child"));
var rootContainer = new CompositionContainer(rootCatalog);
var childContainer = new CompositionContainer(childCatalog, rootContainer);
 
by Glenn Block   January 04, 2010 @ 12:09am
Tags: MEF
117 Views
no comments
 
C#
/*
 
Sample below illustates export inheritance where the base export provides metadata that is overriden by the inheritor
using a custom metadata attribute. 
 
In this case OverridingExtension implements IExtension but then explicitly overrides the base and provides new metadata. 
 
The result is a single export rather than two exports.
 
Notice the inheritor is using an InheritedExport attribute + a custom metadata attribute to override rather than using a custom InheritedExport. 
by Glenn Block   December 13, 2009 @ 1:34pm
Tags: MEF
368 Views
no comments
 
C#
//Design time VM
 
        [Export]
        public ContactVM GetViewModel()
        {
            var contact = new Contact()
            {
                FirstName = "John",
                LastName = "Doe",
                City = "Design time",
by Glenn Block   December 07, 2009 @ 12:39pm
Tags: MEF
518 Views
no comments
 
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