C#依赖库的难题 [英] C# Dependency Library Conundrum

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

问题描述





我有一个有趣的C#难题,我不能想到......或者任何解决方案。



我有两个库 - 称之为 LibA LibB 。这些库之间必须没有依赖关系(即客户端应用程序必须能够使用这些库中的任何一个而没有其他库,并且这两个库都不需要引用或使用语句到其他库)。 />


但是......



客户端应用程序可以 - 可选 - 链接库,因此当运行 LibA 中的某段代码时,它会调用 LibB 中的一段代码。



如果客户端应用程序可以尽可能简单地设置它,也许只需一个函数调用就可以了。



我不确定这个甚至可能,但我会非常有兴趣听到比我更聪明的C#程序员。



亲切的愿望,Patrick

解决方案

除了Andreas Gieriet的回答:

http://en.wikipedia .ORG /维基/的dependency_注入 [ ^ ]。



-SA


依赖注入怎么样?

接口是在LibAContract中定义的和一个LibBContract,甚至是共享的LibContract。

LibA和LibB都依赖合同库并执行相应的合同。

干杯

岸堤

Hi,

I have an interesting C# conundrum, which I can''t think of a neat solution for ... or any solution.

I have two libraries - call them LibA and LibB. There must be no dependency between these libraries (i.e. a client application must be able to use either of these libraries without the other and neither library must require a reference or using statement to the other library).

BUT ...

The client application may - optionally - link the libraries, so that when a certain chunk of code in LibA is run, it calls a piece of code in LibB.

It would also be nice if the client application could set this up as simply as possible, perhaps with a single function call.

I am not sure this is even possible, but I would be extremely interested to hear from wiser C# programmers than I.

Kind wishes, Patrick

解决方案

In addition to the answer by Andreas Gieriet:
http://en.wikipedia.org/wiki/Dependency_injection[^].

—SA


How about Dependency Injection?
The interface is defined in a LibAContract and a LibBContract or even in a shared LibContract.
LibA and LibB depend both on that contract lib and implement the respective contract.
Cheers
Andi


这篇关于C#依赖库的难题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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