2 using System.Windows.Controls;
3 using System.Windows.Navigation;
5 using Caliburn.Micro.Logging;
6 using Pithos.Client.WPF.Caliburn.Micro.Logging;
9 using log4net.Appender;
14 namespace Pithos.Client.WPF
17 using System.Collections.Generic;
18 using System.ComponentModel.Composition;
19 using System.ComponentModel.Composition.Hosting;
20 using System.ComponentModel.Composition.Primitives;
24 public class AppBootstrapper : Bootstrapper<IShell>
26 CompositionContainer container;
28 public AppBootstrapper()
30 log4net.Config.XmlConfigurator.Configure();
32 LogManager.GetLog = type => new log4netLogger(type);
36 /// By default, we are configured to use MEF
38 protected override void Configure() {
39 var catalog = new AggregateCatalog(
40 AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
43 Type[] types = { typeof(PithosMonitor), typeof(CloudFilesClient) };
44 foreach (var type in types)
46 catalog.Catalogs.Add(new AssemblyCatalog(type.Assembly));
49 container = new CompositionContainer(catalog);
51 var batch = new CompositionBatch();
53 batch.AddExportedValue<IWindowManager>(new WindowManager());
54 batch.AddExportedValue<IEventAggregator>(new EventAggregator());
55 batch.AddExportedValue(container);
56 batch.AddExportedValue(catalog);
59 container.Compose(batch);
61 ConventionManager.AddElementConvention<MenuItem>(ItemsControl.ItemsSourceProperty, "DataContext", "Click");
64 protected override object GetInstance(Type serviceType, string key)
66 string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
67 var exports = container.GetExportedValues<object>(contract);
69 if (exports.Count() > 0)
70 return exports.First();
72 throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
75 protected override IEnumerable<object> GetAllInstances(Type serviceType)
77 return container.GetExportedValues<object>(AttributedModelServices.GetContractName(serviceType));
80 protected override void BuildUp(object instance)
82 container.SatisfyImportsOnce(instance);