如何通过另一个DLL访问DLL中的命名空间? [英] How to access namespaces in a DLL via another DLL?

查看:318
本文介绍了如何通过另一个DLL访问DLL中的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个DLL(管理自己或不管理自己),我想包括在CoreLib.dll中,以便我不必在每个使用这些DLL的应用程序中包含(可能)数百个DLL。我将DLL直接包含在DLL中。



所以,我也想在我创建的应用程序中实例化这些DLL中声明的类。我不能做MyApp.exe项目中所描绘的内容,即使我想。 CoreLib中没有提及A,B或C。





如何完成我想要的?



EDIT
我建议使用Facade Pattern,但是我收到一个编译错误。说我要把A.dll包括在MyApp项目中。为什么?这是我想避免的。任何方式?



解决方案

我不认为这是可能的。在CorLib中添加对A,B和C DLL的引用仅意味着CorLib引用这些DLL(AssemblyRef元数据表将为每个程序集创建一个记录)。这并不意味着CorLib重新定义了组件和任何类型的引用程序集。在MyApp.exe中,您需要引用A,B和C程序集。



另一种解决方案是在CorLib中定义Facade类,并将调用重定向到A, B和C DLL。在MyApp.exe中,您将使用Facade类。


I have multiple DLLs (either managed myself or not managed myself) that I would like to include in a CoreLib.dll so that I do not have to include (possibly) hundreds of DLLs in every application that uses these DLLs. I include the DLLs with a reference directly to the DLL.

So, I would also like to instantiate classes declared within those DLLs in the application I am creating. I cannot do what is pictured in MyApp.exe project, even though I would like to. There is no reference to A, B or C in CoreLib.

How can I accomplish what I want?

EDIT I used Facade Pattern as suggested, however I am getting a compilation error. Its saying I have to include A.dll in MyApp project. Why? This is what I wanted to avoid. Any way around this?

解决方案

I do not think this is possible. Adding reference to A, B and C DLLs in CorLib will only mean that CorLib references these DLLs (AssemblyRef metadata table will have one record for each assembly). This does not mean CorLib redefines the assemblies and any types of the referenced assemblies. in MyApp.exe, you would need to reference A, B and C assemblies.

An alternative solution would be to define a Facade class in CorLib and redirect calls to A, B and C DLLs. In MyApp.exe, you will use the Facade class.

这篇关于如何通过另一个DLL访问DLL中的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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