How can MEF resolve dependencies of assemblies that don't live at the root of the application?

丶灬走出姿态 提交于 2020-01-04 05:25:37

问题


I have written my application to be a class library that is launched by a win32 MFC application. Each of my views is a separate assembly that is located with the base class library that is located in a sub-directory of the hosted MFC application.

My question is, how can I get MEF to resolve the dependencies of my exported classes using the assemblies from this sub-directory instead of the root directory?

This is what I want:

ParentFolder
 myapp.exe
 SubFolder
     myMvvmWindow.dll
     myMvvmSubWindow.dll
     *Microsoft.Expression.Interactions.dll*

This is what I have to have now:

  ParentFolder
     myapp.exe
     *Microsoft.Expression.Interactions.dll*
     SubFolder
         myMvvmWindow.dll
         myMvvmSubWindow.dll

回答1:


You can also do this in your app.config file:

Is it possible to set assembly probing path w/o app.config?

This is generally how I handle it.




回答2:


MEF will not handle this scenario for you, as it uses the CLR's normal assembly loading mechanisms to find dependencies.

However, you can easily work around this for a specific subdirectory by handling AppDomain.AssebmlyResolve. If you check your sub folder for the assemblies that don't resolve in your main directory, you can load them yourself and make this function properly.



来源:https://stackoverflow.com/questions/7533233/how-can-mef-resolve-dependencies-of-assemblies-that-dont-live-at-the-root-of-th

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!