首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将项目从Caliburn.Micro转换为“普通”Caliburn的问题

将项目从Caliburn.Micro转换为“普通”Caliburn的问题
EN

Stack Overflow用户
提问于 2010-12-19 21:40:42
回答 1查看 625关注 0票数 0

需要转换项目从caliburn.micro到普通的卡利本。我对bootstraper类有问题。

I caliburn.micro看起来像这样:

代码语言:javascript
复制
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类。我该如何解决这个问题呢?

我需要从外部程序集加载类型。

感谢您的帮助

EN

回答 1

Stack Overflow用户

发布于 2010-12-20 08:40:54

你使用的是最新的源代码吗?Bootstrapper最近被移植回Caliburn。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4483167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档