using System.ComponentModel.Composition.Hosting; using System.ComponentModel.Composition; using Contracts; public class MyApp { [ImportMany(typeof(IService))] public IEnumerable> Services { get; set; } public void Run() { var container = new CompositionContainer(...); container.ComposeParts(this); //Get all the services that implement IService contract var services = container.GetExports (); foreach(var service in services) { service.Value.DoStuff(); } } }
using System.ComponentModel.Composition.Hosting; using System.ComponentModel.Composition; using Contracts; public class MyApp { [ImportMany(typeof(IService))] public IEnumerableIn this example, we use the CompositionContainer to retrieve all the exports that match a metadata value "1.0". These examples demonstrate how to use the CompositionContainer GetExports method to query plugins at runtime based on the contract and metadata. The System.ComponentModel.Composition.Hosting namespace is part of the .Net Framework and can be found in System.ComponentModel.Composition.dll package library.> Services { get; set; } public void Run() { var container = new CompositionContainer(...); container.ComposeParts(this); //Get all the services that have version metadata 1.0 var services = container.GetExports (m => m.Version == "1.0"); foreach(var service in services) { service.Value.DoStuff(); } } }