From a9e4961ea57cc26630f2cf0b5322d5c93fb286ce Mon Sep 17 00:00:00 2001 From: Antony Male Date: Mon, 3 Mar 2014 22:07:33 +0000 Subject: [PATCH] Bit more documentation --- Stylet/ActionExtension.cs | 11 +++++++++++ Stylet/Bootstrapper.cs | 26 ++++++++++++++++++++++++++ Stylet/BootstrapperBase.cs | 19 ++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Stylet/ActionExtension.cs b/Stylet/ActionExtension.cs index 9c332db..b5062cd 100644 --- a/Stylet/ActionExtension.cs +++ b/Stylet/ActionExtension.cs @@ -10,10 +10,20 @@ using System.Windows.Markup; namespace Stylet { + /// + /// MarkupExtension used for binding Commands and Events to methods on the View.ActionTarget + /// public class ActionExtension : MarkupExtension { + /// + /// Name of the method to call + /// public string Method { get; set; } + /// + /// Create a new ActionExtension + /// + /// Name of the method to call public ActionExtension(string method) { this.Method = method; @@ -23,6 +33,7 @@ namespace Stylet { var valueService = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget)); + // Seems this is the case when we're in a template. We'll get called again properly in a second. // http://social.msdn.microsoft.com/Forums/vstudio/en-US/a9ead3d5-a4e4-4f9c-b507-b7a7d530c6a9/gaining-access-to-target-object-instead-of-shareddp-in-custom-markupextensions-providevalue-method?forum=wpf if (!(valueService.TargetObject is FrameworkElement)) return this; diff --git a/Stylet/Bootstrapper.cs b/Stylet/Bootstrapper.cs index e623ec5..6dc87b5 100644 --- a/Stylet/Bootstrapper.cs +++ b/Stylet/Bootstrapper.cs @@ -9,10 +9,20 @@ using System.Windows; namespace Stylet { + /// + /// Bootstrapper to be extended by any application which wants to use StyletIoC (the default) + /// + /// Type of the root ViewModel. This will be instantiated and displayed public class Bootstrapper : BootstrapperBase { + /// + /// IoC container. This is created after ConfigureIoC has been run. + /// protected IContainer container; + /// + /// Called from the constructor, this does everything necessary to start the application, including set up StyletIoC + /// protected override void Start() { base.Start(); @@ -22,6 +32,13 @@ namespace Stylet this.container = builder.BuildContainer(); } + /// + /// Override to add your own types to the IoC container. + /// + /// + /// Don't call the base method if you want to set up your own bindings for IWindowManager, IEventAggregator, IViewManager + /// + /// protected virtual void ConfigureIoC(IStyletIoCBuilder builder) { builder.Autobind(AssemblySource.Assemblies); @@ -31,16 +48,25 @@ namespace Stylet builder.Bind().To().InSingletonScope(); } + /// + /// Override which uses StyletIoC as the implementation for IoC.Get + /// protected override object GetInstance(Type service, string key = null) { return this.container.Get(service, key); } + /// + /// Override which uses StyletIoC as the implementation for IoC.GetAll + /// protected override IEnumerable GetAllInstances(Type service) { return this.container.GetAll(service); } + /// + /// Override which uses StyletIoC as the implementation for IoC.BuildUp + /// protected override void BuildUp(object instance) { this.container.BuildUp(instance); diff --git a/Stylet/BootstrapperBase.cs b/Stylet/BootstrapperBase.cs index 3d2719a..49e0b6f 100644 --- a/Stylet/BootstrapperBase.cs +++ b/Stylet/BootstrapperBase.cs @@ -25,8 +25,16 @@ namespace Stylet // // // And also so that we can load the Stylet resources + + /// + /// Bootstrapper to be extended by applications which don't want to use StyletIoC as the IoC container. + /// + /// Type of the root ViewModel. This will be instantiated and displayed public abstract class BootstrapperBase : ResourceDictionary { + /// + /// Reference to the current application + /// protected Application Application { get; private set; } public BootstrapperBase() @@ -37,23 +45,32 @@ namespace Stylet this.Start(); } + /// + /// Called from the constructor, this does everything necessary to start the application + /// protected virtual void Start() { this.Application = Application.Current; + + // Use the current SynchronizationContext for the Execute helper Execute.SynchronizationContext = SynchronizationContext.Current; + // Make life nice for the app - they can handle these by overriding Bootstrapper methods, rather than adding event handlers this.Application.Startup += OnStartup; this.Application.Exit += OnExit; this.Application.DispatcherUnhandledException += OnUnhandledExecption; + // The magic which actually displays this.Application.Startup += (o, e) => { IoC.Get().ShowWindow(IoC.Get()); }; + // Add the current assembly to the assemblies list - this will be needed by the IViewManager AssemblySource.Assemblies.Clear(); AssemblySource.Assemblies.AddRange(this.SelectAssemblies()); - + + // Stitch the IoC shell to us IoC.GetInstance = this.GetInstance; IoC.GetAllInstances = this.GetAllInstances; IoC.BuildUp = this.BuildUp;