using System; using System.ComponentModel.Composition.Hosting; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.ComponentModel.Composition; using Pithos.Core; namespace Pithos.Client { public class IoC { public CompositionContainer Container; static readonly Lazy Instance=new Lazy(); public static IoC Current { get { return Instance.Value; } } public IoC() { var catalog = new AggregateCatalog(); var executingAssembly = Assembly.GetExecutingAssembly(); catalog.Catalogs.Add(new AssemblyCatalog(executingAssembly)); Type[] types = {typeof (PithosMonitor), typeof (Pithos.Network.CloudFilesClient)}; foreach (var type in types) { catalog.Catalogs.Add(new AssemblyCatalog(type.Assembly)); } Container=new CompositionContainer(catalog); } public T Compose(T target) { try { Container.ComposeParts(target); return target; } catch (Exception exc) { Trace.TraceError(exc.ToString()); throw; } } } }