Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Marco Bertschi 14-Mar-13 16:23pm    
Are LibA and LibB deployed by the same developer(s) as the application which optionally links one of the libraries?
And why do you want to link the libraries "optionally"?

cheers,
Marco Bertschi
Patrick Skelton 14-Mar-13 16:28pm    
One library may generate warnings. The second library handles logging. I want the option of having the warnings (simple text messages) handled by the logging code, but I don't want a dependency because I may later use a different logging library.
Patrick Skelton 15-Mar-13 6:50am    
Sorry - forgot to mention that, yes, at the moment at least, I do have access to all the source code involved in this.

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

—SA
 
Share this answer
 
Comments
Andreas Gieriet 14-Mar-13 18:49pm    
My 5! I was obviously too lazy to add that in my answer... I'll try to improve in the future ;-)
Cheers
Andi
Sergey Alexandrovich Kryukov 14-Mar-13 18:56pm    
It's ok. Teamwork, isn't it?
Thank you, Andi.
—SA
Andreas Gieriet 14-Mar-13 18:59pm    
Right! Thanks! :-)
Andi
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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Mar-13 18:16pm    
Andi,

With my credit to this answer I added a missing reference in mine, please see. I voted 5.

Cheers,
—SA
Andreas Gieriet 14-Mar-13 18:47pm    
Hello Sergey,
Thanks for your 5 and your added reference!
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900