MEF依赖和版本控制 [英] MEF Dependencies and versioning

查看:172
本文介绍了MEF依赖和版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用MEF加载零件的系统。这些部分都依赖于核心库。当我构建项目时,我添加一个版本号到.dll文件,如下所示:




  • part1-1.0.0.0.dll

  • part2-1.0.0.0.dll



此外,还有一个执行MEF组合的应用程序。它还使用核心库。我发现我可以部署部分dll,并且组合工作正常,因为应用程序已经加载了部件所依赖的核心库。所以我的文件系统看起来像这样:




  • /parts/part1-v1.dll

  • /part2-v1.dll

  • composer-v1.exe

  • core-v1.exe



    • 我遇到的麻烦是如何处理核心和部件的版本控制。假设我对核心进行更新,其中一个部分。然后,我部署更改。所以现在我的文件系统可能看起来像:




      • /parts/part1-v1.dll

      • /parts/part1-v2.dll

      • /parts/part2-v1.dll

      • composer-v1.exe

      • core-v1.dll

      • core-v2.dll



      我可以确保part1-v1.dll使用core-v1.dll,而part1-v2.dll使用core-v2.dll吗?我需要所有版本的零件加载,并使用相应版本的核心。



      零件类看起来像这样:

        [Export(typeof(IPart))] 
      public class Part1
      {
      public string GetSomethingFromCore()
      {
      return Core.GetSomethingFromCore();
      }
      }

      [Export(typeof(IPart))]
      public class Part2
      {
      public string GetSomethingFromCore()
      {
      return Core.GetSomethingFromCore();
      }
      }


      解决方案

      强大的命名照顾您的问题?如果一个程序集是针对强大的命名依赖构建的,那么你知道它将只接受与最后一个字节完全相同的依赖。



      或者,如果强命名是太限制了,你可以把类型名称中的版本号。例如:

        [Export(typeof(IPart))] 
      public class Part1v1
      {
      私人只读ICorev1核心;

      [ImportingConstructor]
      public Part1v1(ICorev1 core)
      {
      this.core = core;
      }
      }

      [导出(typeof(IPart))]
      public class Part1v2
      {
      private readonly ICorev2 core;

      [ImportingConstructor]
      public Part1v2(ICorev2 core)
      {
      this.core = 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆