/
Program.cs
40 lines (32 loc) · 1.15 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using CarContract;
namespace CarHost
{
class Program
{
[ImportMany(typeof(ICarContract), AllowRecomposition=true)]
private IEnumerable<ICarContract> CarParts { get; set; }
static void Main(string[] args)
{
new Program().Run();
}
void Run()
{
var aggregateCatalog = new AggregateCatalog();
aggregateCatalog.Catalogs.Add(new DirectoryCatalog(@".\AddIn01"));
var container = new CompositionContainer(aggregateCatalog);
container.ComposeParts(this);
foreach (ICarContract car in CarParts)
Console.WriteLine(car.GetName());
Console.WriteLine("\n...weitere Parts laden...\n");
aggregateCatalog.Catalogs.Add(new DirectoryCatalog(@".\AddIn02"));
container.ComposeParts(this);
foreach (ICarContract car in CarParts)
Console.WriteLine(car.GetName());
container.Dispose();
}
}
}