Removing circular dependency

  • Thread starter =?ISO-8859-2?Q?Krzysztof_Koz=B3owski?=
  • Start date
?

=?ISO-8859-2?Q?Krzysztof_Koz=B3owski?=

Hi all,

I have the following problem: I have 2 namespaces: NamespaceA in
ProjectA, and NamespaceB in ProjectB. NamespaceA contains class ClassA,
which contains a field of type NamespaceB.ClassB. And the other way
around: NamespaceB contains ClassB, containing a field of type
NamespaceA.ClassB. The compiler gives an error saying, that I am missing
the assembly references. So I add ProjectB to the references of
ProjectA, and after that try to add ProjectA to the references of
ProjectB, which Visual Studio does not enable me to do, saying, that
there would be a circular depency. How can I solve this problem?

Regards,

Krzysztof Kozlowski
 
D

David Browne

Krzysztof Koz³owski said:
Hi all,

I have the following problem: I have 2 namespaces: NamespaceA in ProjectA,
and NamespaceB in ProjectB. NamespaceA contains class ClassA, which
contains a field of type NamespaceB.ClassB. And the other way around:
NamespaceB contains ClassB, containing a field of type NamespaceA.ClassB.
The compiler gives an error saying, that I am missing the assembly
references. So I add ProjectB to the references of ProjectA, and after
that try to add ProjectA to the references of ProjectB, which Visual
Studio does not enable me to do, saying, that there would be a circular
depency. How can I solve this problem?

Either change the design, or put both namespaces in the same assembly. If
such interdependency is really appropriate, then the namespaces belong in
the same assembly.

Options for redesign include:

Break out the common bits into a third assembly (possibly using interfaces)
or
Abstract the declared type of one of NamespaceA.ClassA.FieldA to be a
supertype or interface declared in AssemblyA.

Remember that namespaces and assemblies don't have to have to share
boundaries.

David
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

It is a generic software engineering problem it is not specific for C# and
surely it has a generic solution. You should implement a super class that
manages both... In your circumstance, you should add a new project to manage
both..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top