0
プラグインディレクトリにいくつかの拡張プラグインがあります。 ViewModelでプラグインをインポートして使用する予定ですが、インポートは正常にできません。私は助言を求める、私が正常に設定を設定する方法がありませんだと思うCaliburn.microがMEFを使用してカスタムプラグインをインポートする方法
ブートストラップ:実際に
public class AppBootstrapper : BootstrapperBase
{
private CompositionContainer container;
public AppBootstrapper()
{
Initialize();
}
protected override void Configure()
{
string pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins");
if (!Directory.Exists(pluginPath))
Directory.CreateDirectory(pluginPath);
var fi = new DirectoryInfo(pluginPath).GetFiles("*.dll");
AssemblySource.Instance.AddRange(fi.Select(fileInfo => Assembly.LoadFrom(fileInfo.FullName)));
var catalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>());
var batch = new CompositionBatch();
container = new CompositionContainer(catalog);
batch.AddExportedValue(container);
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(catalog);
container.Compose(batch);
}
protected override void BuildUp(object instance)
{
base.BuildUp(instance);
}
protected override object GetInstance(Type service, string key)
{
var contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(service) : key;
var exports = this.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 this.container.GetExportedValues<object>(AttributedModelServices.GetContractName(service));
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<IShell>();
}
}
のViewModel
[ImportMany]
IEnumerable<Lazy<IPlugin, IPluginsMetaData>> plugins;