简体   繁体   English

WPF:如何在Prism + MEF中重新加载AggregateCatalog?

[英]WPF: how to reload AggregateCatalog in Prism + MEF?

How to properly reload Prism's AggregateCatalog ? 如何正确地重新加载Prism的AggregateCatalog? When a file changes, I need Prism to reload its catalog, but it keeps giving me this error: 当文件更改时,我需要Prism重新加载其目录,但它一直给我这个错误:

An unhandled exception of type 'System.ComponentModel.Composition.ChangeRejectedException' occurred in System.ComponentModel.Composition.dll System.ComponentModel.Composition.dll中发生了类型为'System.ComponentModel.Composition.ChangeRejectedException'的未处理异常

Here is the Bootstrapper snippet. 这是自举程序片段。 It fails when I clear the AggregateCatalog. 当我清除AggregateCatalog时,它将失败。

class Bootstrapper : MefBootstrapper
{
    private readonly FileSystemWatcher _fileWatcher;

    public Bootstrapper()
    {
        _fileWatcher = new FileSystemWatcher(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Modules"));
        _fileWatcher.Created += fileWatcher_Changed;
        _fileWatcher.Changed += fileWatcher_Changed;
        _fileWatcher.Deleted += fileWatcher_Changed;
        _fileWatcher.Renamed += fileWatcher_Changed;
        _fileWatcher.EnableRaisingEvents = true;
    }

    private void fileWatcher_Changed(object sender, FileSystemEventArgs e)
    {
        this.AggregateCatalog.Catalogs.Clear(); //It fails here!
        ConfigureAggregateCatalog();
        ConfigureContainer();
    }

It is not possible to do that. 这是不可能的。 When the application starts the module catalog is built during for initialisation and thereafter it is not used anymore and even destroyed. 当应用程序启动时,将在初始化期间构建模块目录,此后将不再使用它,甚至将其销毁。 So dynamically, without restarting the application, adding modules is not possible with prism. 如此动态地在不重新启动应用程序的情况下,使用棱镜无法添加模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM