c# - Solution for circular dependency -
I have two classes in two projects and each class needs to call another class system. But can not add to each other's context because it is making a circular dependency.
I know that I should use an interface to solve this issue, but I am not able to come up with the answer. Please tell me how to implement and amp;
Project Test 2
Nom place Test 2 {Public Class ClassTest2 {Public String GetClassTest2 () {Return to "classTest2"; }}}
Project Test 1
Nom place Test 1 {public class ClassTest1 {public string GetClassTest1 () {"classTest1 "; }}}}
You will need a third project in which you define the interface :
Public Interface ICLASSAnonymous {string GetClassName (); }
From both existing projects, refer to this new assembly and implement the classes interface:
public class ClassTest1: IClassNameAware {public string GetClassName ( ) {Return "classTest1"; }
Now both classes still can not directly reach each other, but they accept IClassNameAware
variable, that is: < / P>
Number of public Bull classmates (ICSNLA Other Other Classes) {GetClassName (return). Equal (other class. Gat classname ()); }}
Comments
Post a Comment