root / trunk / Pithos.ShellExtensions / IoC.cs @ d78cbf09
History | View | Annotate | Download (1 kB)
1 |
using System; |
---|---|
2 |
using System.ComponentModel.Composition.Hosting; |
3 |
using System.Diagnostics; |
4 |
using System.Reflection; |
5 |
using System.ComponentModel.Composition; |
6 |
|
7 |
namespace Pithos.ShellExtensions |
8 |
{ |
9 |
public class IoC |
10 |
{ |
11 |
public CompositionContainer Container; |
12 |
|
13 |
static readonly Lazy<IoC> Instance=new Lazy<IoC>(); |
14 |
|
15 |
public static IoC Current |
16 |
{ |
17 |
get { return Instance.Value; } |
18 |
} |
19 |
|
20 |
public IoC() |
21 |
{ |
22 |
var catalog = new AggregateCatalog(); |
23 |
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); |
24 |
|
25 |
Container=new CompositionContainer(catalog); |
26 |
} |
27 |
|
28 |
|
29 |
|
30 |
public T Compose<T>(T target) |
31 |
{ |
32 |
try |
33 |
{ |
34 |
Container.ComposeParts(target); |
35 |
return target; |
36 |
} |
37 |
catch (Exception exc) |
38 |
{ |
39 |
Trace.TraceError(exc.ToString()); |
40 |
throw; |
41 |
} |
42 |
} |
43 |
} |
44 |
} |