diff options
Diffstat (limited to 'win/CS/HandBrakeWPF/Startup/MefBootstrapper.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/Startup/MefBootstrapper.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/Startup/MefBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/MefBootstrapper.cs new file mode 100644 index 000000000..c03d4baf9 --- /dev/null +++ b/win/CS/HandBrakeWPF/Startup/MefBootstrapper.cs @@ -0,0 +1,53 @@ +namespace HandBrakeWPF.Startup
+{
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel.Composition;
+ using System.ComponentModel.Composition.Hosting;
+ using System.Linq;
+
+ using Caliburn.Micro;
+
+ using HandBrakeWPF.ViewModels.Interfaces;
+
+ public class MefBootstrapper : Bootstrapper<IMainViewModel>
+ {
+ private CompositionContainer container;
+
+ protected override void Configure()
+ {
+ container = new CompositionContainer(
+ new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)))
+ );
+
+ var batch = new CompositionBatch();
+
+ batch.AddExportedValue<IWindowManager>(new WindowManager());
+ batch.AddExportedValue<IEventAggregator>(new EventAggregator());
+ batch.AddExportedValue(container);
+
+ container.Compose(batch);
+ }
+
+ protected override object GetInstance(Type serviceType, string key)
+ {
+ string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
+ var exports = container.GetExportedValues<object>(contract);
+
+ if (exports.Count() > 0)
+ return exports.First();
+
+ throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
+ }
+
+ protected override IEnumerable<object> GetAllInstances(Type serviceType)
+ {
+ return container.GetExportedValues<object>(AttributedModelServices.GetContractName(serviceType));
+ }
+
+ protected override void BuildUp(object instance)
+ {
+ container.SatisfyImportsOnce(instance);
+ }
+ }
+}
\ No newline at end of file |