Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Design Dependency
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 14-Mar-13 11:02am
Comments
Marco Bertschi at 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 at 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 at 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
good
Please Sign up or sign in to vote.

Solution 2

In addition to the answer by Andreas Gieriet:
http://en.wikipedia.org/wiki/Dependency_injection[^].
 
—SA
  Permalink  
Comments
Andreas Gieriet at 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 at 14-Mar-13 18:56pm
   
It's ok. Teamwork, isn't it?
Thank you, Andi.
—SA
Andreas Gieriet at 14-Mar-13 18:59pm
   
Right! Thanks! :-)
Andi
Rate this: bad
good
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.
Cheers
Andi
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 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)

  Print Answers RSS
0 OriginalGriff 499
1 Maciej Los 325
2 Sergey Alexandrovich Kryukov 234
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 14 Mar 2013
Copyright © CodeProject, 1999-2014
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