Modifications to allow synchronization of shared files:
[pithos-ms-client] / trunk / Pithos.Client / IoC.cs
1 using System;
2 using System.ComponentModel.Composition.Hosting;
3 using System.Diagnostics;
4 using System.IO;
5 using System.Linq;
6 using System.Reflection;
7 using System.ComponentModel.Composition;
8 using Pithos.Core;
9
10 namespace Pithos.Client
11 {
12     public class IoC
13     {
14         public CompositionContainer Container;
15         
16         static readonly Lazy<IoC> Instance=new Lazy<IoC>();
17
18         public static IoC Current
19         {
20             get { return Instance.Value; }
21         }
22
23         public IoC()
24         {
25             var catalog = new AggregateCatalog();
26             var executingAssembly = Assembly.GetExecutingAssembly();
27             catalog.Catalogs.Add(new AssemblyCatalog(executingAssembly));
28
29             Type[] types = {typeof (PithosMonitor), typeof (Pithos.Network.CloudFilesClient)};
30             foreach (var type in types)
31             {
32                 catalog.Catalogs.Add(new AssemblyCatalog(type.Assembly));    
33             }
34
35                                 
36             
37             Container=new CompositionContainer(catalog);
38         }
39         
40
41
42         public T Compose<T>(T target)
43         {
44             try
45             {
46                 Container.ComposeParts(target);
47                 return target;
48             }
49             catch (Exception exc)
50             {
51                 Trace.TraceError(exc.ToString());
52                 throw;
53             }
54         }
55     }
56 }