BootstrapperBase is no longer a ResourceDictionary

This commit is contained in:
Antony Male 2014-03-18 21:16:54 +00:00
parent 695a1a345e
commit 7758a2716c
5 changed files with 21 additions and 24 deletions

View File

@ -5,7 +5,9 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<local:HelloBootstrapper/>
<ResourceDictionary>
<local:HelloBootstrapper x:Key="bootstrapper"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

View File

@ -5,7 +5,9 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<local:Bootstrapper/>
<ResourceDictionary>
<local:Bootstrapper x:Key="bootstrapper"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

View File

@ -5,7 +5,9 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<local:Bootstrapper/>
<ResourceDictionary>
<local:Bootstrapper x:Key="bootstrapper"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

View File

@ -5,7 +5,9 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<local:Bootstrapper/>
<ResourceDictionary>
<local:Bootstrapper x:Key="bootstrapper"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

View File

@ -10,27 +10,11 @@ using System.Windows.Threading;
namespace Stylet
{
// We pretend to be a ResourceDictionary so the user can do:
// <Application.Resources><ResourceDictionary>
// <ResourceDictionary.MergedDictionaries>
// <local:Bootstrapper/>
// </ResourceDictionary.MergedDictionaries>
// </ResourceDictionary></Application.Resources>
// rather than:
// <Application.Resources><ResourceDictionary>
// <ResourceDictionary.MergedDictionaries>
// <ResourceDictionary>
// <local:Bootstrapper x:Key="bootstrapper"/>
// </ResourceDictionary>
// </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
public abstract class BootstrapperBase<TRootViewModel>
{
/// <summary>
/// Reference to the current application
@ -39,9 +23,6 @@ namespace Stylet
public BootstrapperBase()
{
var rc = new ResourceDictionary() { Source = new Uri("pack://application:,,,/Stylet;component/Xaml/StyletResourceDictionary.xaml", UriKind.Absolute) };
this.MergedDictionaries.Add(rc);
this.Start();
}
@ -69,6 +50,8 @@ namespace Stylet
// Add the current assembly to the assemblies list - this will be needed by the IViewManager
AssemblySource.Assemblies.Clear();
AssemblySource.Assemblies.AddRange(this.SelectAssemblies());
this.ConfigureResources();
// Stitch the IoC shell to us
IoC.GetInstance = this.GetInstance;
@ -76,6 +59,12 @@ namespace Stylet
IoC.BuildUp = this.BuildUp;
}
protected virtual void ConfigureResources()
{
var rc = new ResourceDictionary() { Source = new Uri("pack://application:,,,/Stylet;component/Xaml/StyletResourceDictionary.xaml", UriKind.Absolute) };
Application.Resources.MergedDictionaries.Add(rc);
}
protected abstract object GetInstance(Type service, string key = null);
protected abstract IEnumerable<object> GetAllInstances(Type service);
protected abstract void BuildUp(object instance);