Re-jig what in the bootstrapper gets called on construction, and what on application startup

This commit is contained in:
Antony Male 2014-04-22 14:51:07 +01:00
parent 8e571dc4c6
commit 12dde3a024
2 changed files with 24 additions and 28 deletions

View File

@ -25,14 +25,14 @@ namespace Stylet
/// </summary>
protected override void Start()
{
base.Start();
var builder = new StyletIoCBuilder();
this.DefaultConfigureIoC(builder);
this.ConfigureIoC(builder);
this.container = builder.BuildContainer();
base.Start();
}
/// <summary>

View File

@ -21,10 +21,26 @@ namespace Stylet
/// </summary>
protected Application Application { get; private set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Start must be overridable. It doesn't depend on the type having been constructed")]
public BootstrapperBase()
{
this.Start();
// 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;
this.Application = Application.Current;
// Call this before calling our Start method
this.Application.Startup += this.OnStartup;
this.Application.Startup += (o, e) => this.Start();
// Make life nice for the app - they can handle these by overriding Bootstrapper methods, rather than adding event handlers
this.Application.Exit += OnExit;
this.Application.DispatcherUnhandledException += OnUnhandledExecption;
}
/// <summary>
@ -32,33 +48,13 @@ namespace Stylet
/// </summary>
protected virtual void Start()
{
this.Application = Application.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) =>
{
// Use the current SynchronizationContext for the Execute helper
Execute.SynchronizationContext = SynchronizationContext.Current;
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());
// Use the current SynchronizationContext for the Execute helper
Execute.SynchronizationContext = SynchronizationContext.Current;
this.ConfigureResources();
this.Configure();
// Stitch the IoC shell to us
IoC.GetInstance = this.GetInstance;
IoC.GetAllInstances = this.GetAllInstances;
IoC.BuildUp = this.BuildUp;
IoC.Get<IWindowManager>().ShowWindow(IoC.Get<TRootViewModel>());
}
protected virtual void ConfigureResources()