summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs')
-rw-r--r--win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs
new file mode 100644
index 000000000..22811d348
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs
@@ -0,0 +1,63 @@
+namespace HandBrakeWPF.Startup
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+
+ using Caliburn.Micro;
+
+ using Castle.Core;
+ using Castle.MicroKernel.Registration;
+ using Castle.Windsor;
+
+ using HandBrakeWPF.ViewModels;
+ using HandBrakeWPF.ViewModels.Interfaces;
+
+ /// <summary>
+ /// The Castle Bootstrapper
+ /// </summary>
+ public class CastleBootstrapper : Bootstrapper<IMainViewModel>
+ {
+ /// <summary>
+ /// The Windsor Container
+ /// </summary>
+ private IWindsorContainer windsorContainer;
+
+ /// <summary>
+ /// Configure Castle Windsor
+ /// </summary>
+ protected override void Configure()
+ {
+ this.windsorContainer = new WindsorContainer();
+ this.windsorContainer.Register(Component.For<IWindowManager>().ImplementedBy<WindowManager>());
+ this.windsorContainer.Register(Component.For<IEventAggregator>().ImplementedBy<EventAggregator>());
+
+ // Shell
+ this.windsorContainer.Register(Component.For<IMainViewModel>().ImplementedBy<MainViewModel>().LifeStyle.Is(LifestyleType.Singleton));
+ }
+
+ protected override IEnumerable<Assembly> SelectAssemblies()
+ {
+ return AppDomain.CurrentDomain.GetAssemblies();
+ }
+
+ protected override object GetInstance(Type service, string key)
+ {
+ return string.IsNullOrWhiteSpace(key) ? this.windsorContainer.Resolve(service) : this.windsorContainer.Resolve(key, new { });
+ }
+
+ protected override IEnumerable<object> GetAllInstances(Type service)
+ {
+ return this.windsorContainer.ResolveAll(service).Cast<object>();
+ }
+
+ protected override void BuildUp(object instance)
+ {
+ instance.GetType().GetProperties()
+ .Where(property => property.CanWrite && property.PropertyType.IsPublic)
+ .Where(property => this.windsorContainer.Kernel.HasComponent(property.PropertyType))
+ .ForEach(property => property.SetValue(instance, this.windsorContainer.Resolve(property.PropertyType), null));
+ }
+ }
+}