views:

176

answers:

9

I have 2 projects.

Project#2 has a reference to Project#1

Now I need to reference Project#2 in Project#1, but vs.net is complaining about a circular dependency.

Is there a way out of this?

+4  A: 

Merge the two into one or redesign.

David M
+3  A: 

No. Structure your projects properly. Try using some sort of ordering based on abstraction - low-level to high-level.

wj32
+3  A: 

This points to a problem in your design. If there is a genuine need for two or more of your types to be mutually aware then they should exist in the same assembly.

AdamRalph
+3  A: 

Refactor your projects to take the common elements out into a "Project #0" which both Project #1 and Project #2 reference.

codekaizen
+2  A: 

I really don't mean to be a smart-aleck, but better program design is the answer.

David Stratton
+1  A: 

A circular dependency means that these are no longer two independent projects (because there it is impossible to build only one of them).

You need to either refactor so that you have only a one way dependency or you should merge them into a single project.

R Samuel Klatchko
+11  A: 

Absolutely not. Circular dependencies are a indication of bad design. I don't mean to be harsh. There are some ways out of this.

1) You can refactor common code to another project, say Project#0

2) You can fix your design, which is probably the way to go.

Uncle Bob has a good article on Packaging Principles which includes the Acyclic Dependencies Principle. http://www.objectmentor.com/resources/articles/granularity.pdf. Read this to know why cyclic dependencies are a bad thing.

Craig Wilson
A common fix is to depend on abstractions such as interfaces rather than concrete instances, and to move those abstractions to another assembly. But, really, think about your project structure and what really belongs where.
kyoryu
A: 

Circular reference can be done as seen in a previous question, but you should not do it for the reasons everybody already stated here.

Alfred Myers
A: 

This seems to be a design flaw, nothing else. Re-design is the solution.

Amit