MEF依赖和版本 [英] MEF Dependencies and versioning
问题描述
我有一个使用MEF加载部件的系统。每一部分都依赖于一个核心库。当我建这个项目,我想补充一个版本号为.dll文件是这样的:
- part1-1.0.0.0.dll
- part2-1.0.0.0.dll
此外,还有执行MEF组合物的应用程序。它还采用了核心库。我发现,我可以只部署部分dll文件,并组成工作正常,因为应用程序已经加载的部分依赖核心库。所以,我的文件系统看起来是这样的:
- /parts/part1-v1.dll
- /parts/part2-v1.dll
- 作曲家v1.exe
- 核心v1.exe
我遇到的麻烦是如何处理的核心和部分版本。假如我做一个更新的核心,以及部分之一。然后,我部署的变化。所以现在我的文件系统可能看起来是这样的:
- /parts/part1-v1.dll
- /parts/part1-v2.dll
- /parts/part2-v1.dll
- 作曲家v1.exe
- 核心v1.dll
- 核心v2.dll
我如何能够确保第一部分 - v1.dll采用核心v1.dll,和第1部分,v2.dll采用核心v2.dll?我需要加载和使用该芯的适当版本的所有版本的部件的
部分类看起来是这样的:
[导出(typeof运算(IPART))]
公共类第一部分
{
公共字符串GetSomethingFromCore()
{
返回Core.GetSomethingFromCore();
}
}
[导出(typeof运算(IPART))]
公共类第二部分
{
公共字符串GetSomethingFromCore()
{
返回Core.GetSomethingFromCore();
}
}
不强命名一>把你的问题的关心?如果一个组件对建立一个强大的命名依赖,那么你就知道,这将只接受完全一样的依赖下降到最后一个字节。
另外,如果强命名太严格,你可以把版本号的类型名称。例如:
[导出(typeof运算(IPART))]
公共类Part1v1
{
私人只读ICorev1核心;
[ImportingConstructor]
公共Part1v1(ICorev1芯)
{
this.core =核心;
}
}
[导出(typeof运算(IPART))]
公共类Part1v2
{
私人只读ICorev2核心;
[ImportingConstructor]
公共Part1v2(ICorev2芯)
{
this.core =核心;
}
}
I have a system that uses MEF to load parts. Each of these parts rely on a core library. When I build the project, I add a version number to the .dll files like this:
- part1-1.0.0.0.dll
- part2-1.0.0.0.dll
Also, there is an application that performs MEF composition. It also uses the core library. I've found that I can just deploy the "part" dlls, and composition works fine because the application has already loaded the core library that the parts rely on. So my file system looks something like this:
- /parts/part1-v1.dll
- /parts/part2-v1.dll
- composer-v1.exe
- core-v1.exe
The trouble I'm having is how to handle versioning of the core and parts. Suppose I make an update to the core, and one of the parts. Then, I deploy the changes. So now my file system might look something like:
- /parts/part1-v1.dll
- /parts/part1-v2.dll
- /parts/part2-v1.dll
- composer-v1.exe
- core-v1.dll
- core-v2.dll
How can I make sure that part1-v1.dll uses core-v1.dll, and part1-v2.dll uses core-v2.dll? I need all versions of the parts to be loaded and using the appropriate version of the core.
The part classes look something like this:
[Export(typeof(IPart))]
public class Part1
{
public string GetSomethingFromCore()
{
return Core.GetSomethingFromCore();
}
}
[Export(typeof(IPart))]
public class Part2
{
public string GetSomethingFromCore()
{
return Core.GetSomethingFromCore();
}
}
Doesn't strong naming take care of your issue? If an assembly is build against a strong named dependency, then you know that it will only accept the exact same dependency down to the last byte.
Alternatively, if strong naming is too restrictive, you could put version numbers in the type names. For example:
[Export(typeof(IPart))]
public class Part1v1
{
private readonly ICorev1 core;
[ImportingConstructor]
public Part1v1(ICorev1 core)
{
this.core = core;
}
}
[Export(typeof(IPart))]
public class Part1v2
{
private readonly ICorev2 core;
[ImportingConstructor]
public Part1v2(ICorev2 core)
{
this.core = core;
}
}
这篇关于MEF依赖和版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!