Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference in two projects

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 in P2?

If it is possible? If yes, then how?

like image 783
Naila Akbar Avatar asked Dec 10 '15 12:12

Naila Akbar


People also ask

What is references in projects?

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.

How do you check references in a project?

You can view references in Project Explorer or when you click References on the Tools menu.


1 Answers

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.

like image 89
Patrick Hofman Avatar answered Oct 02 '22 22:10

Patrick Hofman