更新
This commit is contained in:
66
AntdWpfDemo/Bootstrapper.cs
Normal file
66
AntdWpfDemo/Bootstrapper.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.ComponentModel.Composition.Hosting;
|
||||
using System.ComponentModel.Composition.Primitives;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
using Caliburn.Micro;
|
||||
|
||||
namespace AntdWpfDemo
|
||||
{
|
||||
internal class Bootstrapper : BootstrapperBase
|
||||
{
|
||||
private CompositionContainer container;
|
||||
|
||||
public Bootstrapper()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
protected override void Configure()
|
||||
{
|
||||
var catalog = new AggregateCatalog(
|
||||
AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
|
||||
);
|
||||
|
||||
container = new CompositionContainer(catalog);
|
||||
var batch = new CompositionBatch();
|
||||
|
||||
batch.AddExportedValue<IWindowManager>(new WindowManager());
|
||||
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
|
||||
batch.AddExportedValue(container);
|
||||
|
||||
container.Compose(batch);
|
||||
}
|
||||
|
||||
protected override object GetInstance(Type service, string key)
|
||||
{
|
||||
string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(service) : key;
|
||||
var exports = container.GetExportedValues<object>(contract);
|
||||
|
||||
if (exports.Any())
|
||||
{
|
||||
return exports.First();
|
||||
}
|
||||
|
||||
throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
|
||||
}
|
||||
|
||||
protected override IEnumerable<object> GetAllInstances(Type service)
|
||||
{
|
||||
return container.GetExportedValues<object>(AttributedModelServices.GetContractName(service));
|
||||
}
|
||||
|
||||
protected override void BuildUp(object instance)
|
||||
{
|
||||
container.SatisfyImportsOnce(instance);
|
||||
}
|
||||
|
||||
protected override void OnStartup(object sender, StartupEventArgs e)
|
||||
{
|
||||
DisplayRootViewFor<IShell>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user