For Programmers: Free Programming Magazines  


Home > Archive > C# > May 2005 > Circular dependency problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Circular dependency problem
Krzysztof Kozłowski

2005-05-14, 4:04 pm

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
Bruce Wood

2005-05-16, 8:57 am

Could you be more specific as to what these classes are and what they
do?

Lorad

2005-05-17, 8:58 pm

> 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
>


The only way to do this is to use interfaces in at least one of the
projects. I am not sure how this would ever work though.

ClassA
ItemB
ItemA
ItemB1
ItemA1
.... for ever

This is a bad thing. It seems like you have a base set of information that 2
classes need. The fact that C# does not create the actual class right away
saves you from that, but somehow you have to tell the ItemB that you do not
want to create an ItemA when you create it in a parent ItemA.

The following would seem a more logical class layout.

ClassA - all the items and information ClassBChild will have to access (or
your ClassB in existing class)
ClassB - all the items and information ClassAChild will have to access (or
your ClassA in existing class)

ClassAChild
ClassB item
ClassBChild
ClassA item


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com