how resolve this circular reference issue?

C

ChrisB

Hello,

I was wondering what options are available for resolving the following
(simplified) scenario.

Two project exist and each contains a class:
ProjectA - Class1
ProjectB - Class2

Additionally, Class2 needs to accept Class1 as a parameter:
public class Class2
{
// results in circular reference
public static void CompleteAction(Class1 Class1)
}

Because Class1 needs a reference to ProjectB to access the Class2 static
method, and Class2 needs a reference to ProjectA because of the Class1
parameter, a circular reference is created. Is there any way to resolve
this issue short of combining classes 1 and 2 in the same assembly?

Thanks,
Chris
 
M

Mattias Sjögren

Because Class1 needs a reference to ProjectB to access the Class2 static
method, and Class2 needs a reference to ProjectA because of the Class1
parameter, a circular reference is created. Is there any way to resolve
this issue short of combining classes 1 and 2 in the same assembly?

Add an interface IClass1 in a third assembly. reference it from both
projects. Implement it in Class1 and change the parameter type of
CompleteAction to IClass1.


Mattias
 

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

Top