ã¯ããã¦ã®MEFãã®ï¼
MEFã®ããã¥ã¡ã³ããèªãã§ããããã¡ã½ãããã¤ã³ã¸ã§ã¯ã·ã§ã³å¯è½(Seasar.NETã®ã¡ã½ããã¤ã³ã¸ã§ã¯ã·ã§ã³ã§ã¯ãªã)ã¨ãã£ãã®ã§æ©éå®é¨åã
using System; using System.Reflection; using System.Linq; using System.Linq.Expressions; using System.ComponentModel.Composition; public class Foo { [Export("Add")] public int Add(int x, int y) { return x + y; } [Export("Sub")] public int Sub(int x, int y) { return x - y; } } public class Bar { [Export("Mul")] public int Mul(int x, int y) { return x * y; } [Export("Div")] public int Div(int x, int y) { return x / y; } } public class Calc { // ã¡ã½ãããã¤ã³ã¸ã§ã¯ã·ã§ã³ãã [Import("Add")] public Func<int, int, int> Add { get; set; } [Import("Sub")] public Func<int, int, int> Sub { get; set; } [Import("Mul")] public Func<int, int, int> Mul { get; set; } [Import("Div")] public Func<int, int, int> Div { get; set; } } static class Program { public static void Main() { // å®è¡ã¢ã¸ã¥ã¼ã«å ã®ã¯ã©ã¹ãã¤ã³ã¸ã§ã¯ã·ã§ã³ãã var asm = Assembly.GetExecutingAssembly(); var catalog = new AttributedAssemblyPartCatalog(asm); var container = new CompositionContainer(catalog.CreateResolver()); var calc = new Calc(); container.AddPart(calc); container.Compose(); Console.WriteLine (calc.Add(5,2)); Console.WriteLine (calc.Sub(5,2)); Console.WriteLine (calc.Mul(5,2)); Console.WriteLine (calc.Div(5,2)); } } /* çµæ 7 3 10 2 */
mixinã£ã½ãï¼