如何在同一应用程序域中的两个不同dll之间传输数据 [英] How to transfer data between two different dlls in the same app domain

查看:251
本文介绍了如何在同一应用程序域中的两个不同dll之间传输数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我在同一应用程序域中的同一进程中有3个不同的dll运行。

这些dll用作执行该程序的企业软件的插件dll。

dll在同一台机器上运行。

我可以将数据从企业软件传递到dll但我不能将数据从一个dll传递到另一个。

我可以更改dll但我不能在它们之间合并。

我无法对企业软件进行更改。

如何在运行模式下将数据从一个dll传递到另一个dll(我需要以高频率传递数据)。

谢谢

解决方案

DLL之间唯一的障碍可能是访问修饰符 internal 。甚至这个障碍也可以通过反射打破,但你根本不需要它。



首先,你不应该考虑DLL。 .NET的核心模块化概念是程序集,DLL只不过是文件命名约定;至于文件本身,它只不过是程序集的模块。严格来说,每个组件可以由多个模块组成,不止一个,但通常只处理单模块组件;这就是Visual Studio默认创建的内容。



如果在应用程序中使用多个程序集,它们都是相互引用以通过主应用程序程序集加载,直接您是否以与所有代码在同一个程序集中完全相同的方式访问事物,只有一个区别: internal 声明使类型和类型成员可以在任何类型的相同的程序集,但跨程序集访问需要 public internal 。请参阅:

访问修饰符(C#编程指南) [< a href =https://msdn.microsoft.com/en-us/library/ms173121.aspxtarget =_ blanktitle =New Window> ^ ],

访问修饰符(C#参考) [ ^ ],

了解和使用.NET中的程序集和命名空间 [ ^ ]。



这就是全部。 我认为我不需要涵盖反思主题。







在我阅读下面引用的评论后,我抓住了关于上面反思的判断。



会员11326763写道:



我无法从主程序传递它,或者从另一个程序中调用一个dll,因为我只将插件(dll)写入系统。

每个dll都实现了一个复杂的模块,我不能在它们之间混合(dll在运行模式下通过反射加载)。

所以,如果你有任何优雅的解决方案我很高兴。

如果涉及到插件,我必须涵盖基于反射的方法。请参阅我过去在相关主题上的答案,所有这些都在本文中引用:访问驻留在插件dll中的自定义对象 [ ^ ]。



这些主题相对复杂,特别是如果你需要卸载一些插件来重新加载不同的一次;我希望你不要。



一种替代方法是使用Microsoft框架实现可扩展性,MEF:

托管可扩展性框架 - 维基百科,免费的百科全书 [ ^ ],

托管扩展框架 - 主页 [ ^ ],

托管扩展框架(MEF) [ ^ ]。



从Visual Studio 2010和.NET v.4开始,您不需要从CodePlex下载MEF,它已经捆绑了。



-SA

Hello !
I have 3 diffrent dll's that runinig in the same process in the same app domain.
The dll's are use as plugins for enterprise software that execute the dlls.
The dlls are running on the same machine.
I can pass data from the enterprise software to the dlls but I can't pass data from one dll to the another.
I can change the dlls but I cant merge between them.
I can't make a change in the enterprise software.
How I can pass data from one dll to the another in running mode (I need to pass data in high freq).
Thanks

解决方案

The only barrier between DLLs could be the access modifier internal. And even this barrier can be broken via reflection, but you don't need it at all.

First of all, you should not think in terms of DLLs. The central modularity concept of .NET is assembly, and "DLL" is nothing but a file naming convention; as to the file itself, it's nothing but a module of an assembly. Strictly speaking, each assembly can be composed from several modules, more than one, but usually you deal with only single-module assemblies; this is what Visual Studio creates by default.

If you use several assemblies in your application, they all are reference each other to be loaded through the main application assembly, directly or not, you access things in exact same way as all code was in the same assembly, with only one difference: internal declarations make types and type member accessible between any types of the same assembly, but access across assemblies requires public or internal. Please see:
Access Modifiers (C# Programming Guide)[^],
Access Modifiers (C# Reference)[^],
Understanding and Using Assemblies and Namespaces in .NET[^].

That's all. I don't think I need to cover reflection topics.

[EDIT]

I scratched out my sentence about reflection above after I read the comment quoted below.

Member 11326763 wrote:


I can't pass it from the main program , or call one dll from another one, because I only write the plugins (dll's) to the system.
And each dll implement a complex module , and I can't mix between them (the dll's load by reflection in running mode) .
So if you have any elegant solution I will happy.

If it comes to plug-ins, I have to cover approaches based on reflection. Please see my past answers on related topics, all referenced in this one: Access a custom object that resides in plug in dll[^].

These topics are relatively complicated, especially if you have a need to unload some plug-ins to reload different once; I hope you don't.

One alternative approach is using the Microsoft framework for extensibility, MEF:
Managed Extensibility Framework — Wikipedia, the free encyclopedia[^],
Managed Extensibility Framework — Home[^],
Managed Extensibility Framework (MEF)[^].

Starting with Visual Studio 2010 and .NET v.4, you don't need to download MEF from CodePlex, it is already bundled.

—SA


这篇关于如何在同一应用程序域中的两个不同dll之间传输数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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