diff options
author | sr55 <[email protected]> | 2011-09-17 20:49:08 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-09-17 20:49:08 +0000 |
commit | d145ee9d9ed7be65b83124afbf0cc71b60adddc6 (patch) | |
tree | 8a7a47aa0bbeab6b18d6859bc457a215c5cbe61d /win/CS/HandBrakeWPF/Startup/MefBootstrapper.cs | |
parent | ac48779d6481154c16419d3c758af39ddcba4d86 (diff) |
HandBrakeWPF: Switch from Caliburn to Caliburn Micro and Add a CastleWindsor Bootstrapper.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4230 b64f7644-9d1e-0410-96f1-a4d463321fa5
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 |