Bit more documentation

This commit is contained in:
Antony Male 2014-03-03 22:07:33 +00:00
parent 92568e0cbf
commit a9e4961ea5
3 changed files with 55 additions and 1 deletions

View File

@ -10,10 +10,20 @@ using System.Windows.Markup;
namespace Stylet
{
/// <summary>
/// MarkupExtension used for binding Commands and Events to methods on the View.ActionTarget
/// </summary>
public class ActionExtension : MarkupExtension
{
/// <summary>
/// Name of the method to call
/// </summary>
public string Method { get; set; }
/// <summary>
/// Create a new ActionExtension
/// </summary>
/// <param name="method">Name of the method to call</param>
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;

View File

@ -9,10 +9,20 @@ using System.Windows;
namespace Stylet
{
/// <summary>
/// Bootstrapper to be extended by any application which wants to use StyletIoC (the default)
/// </summary>
/// <typeparam name="TRootViewModel">Type of the root ViewModel. This will be instantiated and displayed</typeparam>
public class Bootstrapper<TRootViewModel> : BootstrapperBase<TRootViewModel>
{
/// <summary>
/// IoC container. This is created after ConfigureIoC has been run.
/// </summary>
protected IContainer container;
/// <summary>
/// Called from the constructor, this does everything necessary to start the application, including set up StyletIoC
/// </summary>
protected override void Start()
{
base.Start();
@ -22,6 +32,13 @@ namespace Stylet
this.container = builder.BuildContainer();
}
/// <summary>
/// Override to add your own types to the IoC container.
/// </summary>
/// <remarks>
/// Don't call the base method if you want to set up your own bindings for IWindowManager, IEventAggregator, IViewManager
/// </remarks>
/// <param name="builder"></param>
protected virtual void ConfigureIoC(IStyletIoCBuilder builder)
{
builder.Autobind(AssemblySource.Assemblies);
@ -31,16 +48,25 @@ namespace Stylet
builder.Bind<IViewManager>().To<ViewManager>().InSingletonScope();
}
/// <summary>
/// Override which uses StyletIoC as the implementation for IoC.Get
/// </summary>
protected override object GetInstance(Type service, string key = null)
{
return this.container.Get(service, key);
}
/// <summary>
/// Override which uses StyletIoC as the implementation for IoC.GetAll
/// </summary>
protected override IEnumerable<object> GetAllInstances(Type service)
{
return this.container.GetAll(service);
}
/// <summary>
/// Override which uses StyletIoC as the implementation for IoC.BuildUp
/// </summary>
protected override void BuildUp(object instance)
{
this.container.BuildUp(instance);

View File

@ -25,8 +25,16 @@ namespace Stylet
// </ResourceDictionary.MergedDictionaries>
// </ResourceDictionary></Application.Resources>
// And also so that we can load the Stylet resources
/// <summary>
/// Bootstrapper to be extended by applications which don't want to use StyletIoC as the IoC container.
/// </summary>
/// <typeparam name="TRootViewModel">Type of the root ViewModel. This will be instantiated and displayed</typeparam>
public abstract class BootstrapperBase<TRootViewModel> : ResourceDictionary
{
/// <summary>
/// Reference to the current application
/// </summary>
protected Application Application { get; private set; }
public BootstrapperBase()
@ -37,23 +45,32 @@ namespace Stylet
this.Start();
}
/// <summary>
/// Called from the constructor, this does everything necessary to start the application
/// </summary>
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<IWindowManager>().ShowWindow(IoC.Get<TRootViewModel>());
};
// 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;