简体   繁体   English

如何在 System.AddIn 中使用 automapper?

[英]How do I use automapper with System.AddIn?

In the System.AddIn (aka MAF) pipeline adapters, there is a lot of manual copying of values from one DTO type to another - from HostView types to Pipeline Contract types and from Pipeline Contract types to AddIn view types (and back again).在 System.AddIn(又名 MAF)管道适配器中,有大量的手动将值从一种 DTO 类型复制到另一种类型 - 从 HostView 类型到 Pipeline Contract 类型以及从 Pipeline Contract 类型到 AddIn 视图类型(然后再返回)。 This seems like an ideal situation to use automapper.这似乎是使用 automapper 的理想情况。

However I am unsure as to the correct way to use and package 3rd party assemblies in the HostView and AddInView adapters, especially when AddIn activation is in a separate AppDomain.但是,我不确定在 HostView 和 AddInView 适配器中使用和打包第 3 方程序集的正确方法,尤其是当 AddIn 激活位于单独的 AppDomain 中时。

I tried the following:我尝试了以下方法:

  • add nuget reference for automapper to AddIn adapter project and create the mapping profiles within.将 automapper 的 nuget 引用添加到 AddIn 适配器项目并在其中创建映射配置文件。 (I used a static ctor to the adapter that initializes the profiles cos MAF is responsible for instantiating the adapter.) (我对适配器使用了一个静态构造函数来初始化配置文件,因为 MAF 负责实例化适配器。)

  • Counter-intuitively, to get the pipeline to locate and activate AddIns supported by the adapter, I had to ensure that the automapper DLL lived in the bin dir of my Host - having the automapper DLL in the "AddInAdapters" folder beside the actual adapter DLL had no effect.与直觉相反,为了让管道找到并激活适配器支持的加载项,我必须确保自动映射器 DLL 位于我的主机的 bin 目录中 - 将自动映射器 DLL 放在实际适配器 DLL 旁边的“AddInAdapters”文件夹中没有效果。

With this arrangement, I was able to find and activate the AddIn on my dev box (win 7).通过这种安排,我能够在我的开发箱(win 7)上找到并激活插件。 But the exact same binaries would not work on Server2008R2.但是完全相同的二进制文件在 Server2008R2 上不起作用。 (I know, I know: I don't control the choice of development or server OS) (我知道,我知道:我不控制开发或服务器操作系统的选择)

We are using (and targeting) .Net 4.5.1 - yep, it's on desktop and server.我们正在使用(和定位).Net 4.5.1 - 是的,它在台式机和服务器上。 We are using automapper 2.2.1 - nope, it's not in the GAC of my dev box我们正在使用 automapper 2.2.1 - 不,它不在我的开发箱的 GAC 中

Where should 3rd party assemblies used by Adapters be located (both AddIn side and Host side).适配器使用的第 3 方程序集应位于何处(插件端和主机端)。 Especially when considering AppDomain isolation特别是在考虑 AppDomain 隔离时

Why would the above arrangement work on Windows 7, but not 2008R2?为什么上述安排适用于 Windows 7,而不适用于 2008R2?

On the host side, it should live in the root output directory of your application.在主机端,它应该位于应用程序的根输出目录中。 All of the host dlls are loaded in your app domain and the assembly resolver will look in the location of your running assembly for the automapper dll.所有主机 dll 都加载到您的应用程序域中,程序集解析器将在您正在运行的程序集的位置中查找 automapper dll。

On the Addin side, it should live in the addin adapter directory.在插件端,它应该位于插件适配器目录中。 The addin adapter and addin view are loaded into the new app domain and require their own copy of this dll.插件适配器和插件视图被加载到新的应用程序域中,并且需要它们自己的这个 dll 的副本。

One thing to be careful with when using third party libraries anywhere in your pipeline is it can make versioning your pipeline painful.在您的管道中的任何地方使用第三方库时要小心的一件事是,它会使您的管道版本化变得痛苦。 If you are loading multiple versions of your pipeline to allow for V1 and V2 addins to still work, if they depend on different versions of an assembly, you may run into problems in reconciling this.如果您正在加载管道的多个版本以允许 V1 和 V2 插件仍然工作,如果它们依赖于不同版本的程序集,您可能会在协调这一点时遇到问题。 If you don't care about pipeline versioning, then this is less of a concern.如果您不关心管道版本控制,那么这就不那么重要了。

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

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