c# - Solution for circular dependency -
c# - Solution for circular dependency -
i have below 2 classes in 2 projects , each class needs phone call other class method. cannot add together reference each other because creating circular dependency.
i know must utilize interface resolve issue not able comeup answer. please allow me know how implement & resolve this.
project test2
namespace test2 { public class classtest2 { public string getclasstest2() { homecoming "classtest2"; } } }
project test1
namespace test1 { public class classtest1 { public string getclasstest1() { homecoming "classtest1"; } } }
you'd need 3rd project in define interface:
public interface iclassnameaware { string getclassname(); }
from both existing projects, reference new assembly , create classes implement interface:
public class classtest1 : iclassnameaware { public string getclassname() { homecoming "classtest1"; }
now both classes still can't access eachother directly, take iclassnameaware
variables, ie:
public bool classnamesequal(iclassnameaware otherclass) { homecoming getclassname().equals(otherclass.getclassname()); } }
c# .net visual-studio-2012 interface circular-dependency
Comments
Post a Comment