I've two projects say P1
and P2
.
P1 has a reference of P2.
so I can access P2's methods
from P1
. But what if I want to access P1's methods
from P2
then how can I access them?
I know I can't add
P1's
reference inP2
?
If it is possible? If yes, then how?
A reference is essentially an entry in a project file that contains the information that Visual Studio needs to locate the component or the service.
You can view references in Project Explorer or when you click References on the Tools menu.
As others pointed out circular references are the problem. It can't compile P2 before it has compiled P1, but if P1 depends on P2 it can't compile P1 it until P2 has compiled... Got the problem?
Now the solutions:
The easy way out: Create a shared library where you put in your shared code of P1 and P2. This shared project can be referenced by both P1 and P2.
The better solution: Create an interface which you define in a shared library. Base your 'references' of P2 in P1 on the shared interface, not on the actual implementation. In that way you have a better testable solution and it is easier to replace parts of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With