2010-12-19 43 views
0

需要将项目从caliburn.micro转换为正常校准。我有Bootstraper类的问题。将项目从Caliburn.Micro转换为“常规”Caliburn的问题

我caliburn.micro这个样子:

public class MefBootStrapper : BootStraper<IShellViewModel> 
{ 
#region Fields 
private CompositionContainer _container; 
#endregion 

#region Overrides 
protected override void Configure() 
{ // configure container 
#if SILVERLIGHT 
    _container = CompositionHost.Initialize(
    new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>())); 
#else 

    var catalog = 
     new AggregateCatalog(
      AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()); 

    //add external DLL 
    catalog.Catalogs.Add(
     new AssemblyCatalog(string.Format(
      CultureInfo.InvariantCulture, "{0}{1}", System.IO.Directory.GetCurrentDirectory(), @"\Pokec_Toolkit.dll"))); 

    _container = new CompositionContainer(catalog); 
#endif 

    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 serviceType, string key) 
{ 
    string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key; 
    var exports = _container.GetExportedValues<object>(contract); 

    if (exports.Count() > 0) 
    return exports.First(); 

    throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract)); 
} 

protected override IEnumerable<object> GetAllInstances(Type serviceType) 
{ 
    return _container.GetExportedValues<object>(AttributedModelServices.GetContractName(serviceType)); 
} 

protected override void BuildUp(object instance) 
{ 
    _container.SatisfyImportsOnce(instance); 
} 

protected override IEnumerable<System.Reflection.Assembly> SelectAssemblies() 
{ 
    return base.SelectAssemblies(); 
} 
#endregion 
} 

我使用MEF上注射。

问题出在Caliburn不存在BooStraper类。我该如何解决这个问题?

我需要来自外部装配的负载类型。

感谢帮助

回答

0

您是否正在使用最新的源代码? Bootstrapper最近被移植回Caliburn。