Click here to Skip to main content
11,930,788 members (56,581 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Design Dependency

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 14-Mar-13 11:02am
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"?

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

In addition to the answer by Andreas Gieriet:[^].

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 ;-)
Sergey Alexandrovich Kryukov 14-Mar-13 18:56pm
It's ok. Teamwork, isn't it?
Thank you, Andi.
Andreas Gieriet 14-Mar-13 18:59pm
Right! Thanks! :-)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Sergey Alexandrovich Kryukov 14-Mar-13 18:16pm

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

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 14 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100