Skip to content

Instantly share code, notes, and snippets.

@runceel
Created May 8, 2012 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runceel/2632442 to your computer and use it in GitHub Desktop.
Save runceel/2632442 to your computer and use it in GitHub Desktop.
MEF2 Code sample
void Main()
{
var catalog = new AssemblyCatalog(typeof(A<>).Assembly);
var container = new CompositionContainer(catalog);
var a = container.GetExportedValue<A<string>>();
a.Dump();
container.ComposeParts(this);
var export = this.AProperty.CreateExport();
var value = export.Value;
(value == export.Value).Dump(); // true
(value == export.Value).Dump(); // true
var export2 = this.AProperty.CreateExport();
(value == export2.Value).Dump(); // false
}
// ExportFactory sample
[Import]
public ExportFactory<A<int>> AProperty { get; set; }
// Generic export
[Export(typeof(A<>))]
[PartCreationPolicy(CreationPolicy.Any)]
public class A<T> { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment