开发者

Prism / MEF -- Once my app is running, how do I add to my AggregateCatalog later on?

开发者 https://www.devze.com 2023-02-16 02:33 出处:网络
Basically, I have the following scenario: User runs application The Bootstrapper loads the \"Modules\" directory into the AggregateCatalog.

Basically, I have the following scenario:

  1. User runs application
  2. The Bootstrapper loads the "Modules" directory into the AggregateCatalog.
  3. My navigation menu is built
  4. The user clicks refresh
  5. The app downloads a new module and copies it into the Module directory.

I somehow need to be able to add in the new module to my AggregateCatal开发者_运维百科og and update my navigation menu. I figure a "AllowRecomposition" is necessary, but how do I actually add the new assembly to my AggregateCatalog after my app is already running?


If you import the AggregateCatalog you can access it from within your ViewModel (or wherever else you want to add to it.

[Import()]
private AggregateCatalog _aggregateCatalog;

...

private void SomeFunc()
{
    _aggregateCatalog.Catalogs.Add(...);
}


NOTE: If the Assembly would affect any Import or ImportMany statements, they must allow for recomposition or you will get an exception. For example, if your assembly contains another IFooService export...

//Exception Thrown
[ImportMany(typeof(IFooService))]
private IEnumerable<IFooService> _myFooServices;

//No Exception Thrown
[ImportMany(typeof(IFooService), AllowRecomposition = true)]
private IEnumerable<IFooService> _myFooServices;


NOTE: You will trigger OnImportsSatisfied if you implemented the IPartImportsSatisfiedNotification interface again, so ensure that your application does not have issues because of this.

0

精彩评论

暂无评论...
验证码 换一张
取 消