4

I have a scenario where i need to call classes present in project B from project A. I can not add reference of B in A, due to circular reference issue.

Is there a way to call class present in another function without adding references?

Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
Manish Makkad
  • 237
  • 1
  • 5
  • 13
  • 4
    If you have that situation, you need to think why is that happening and probably refactor your code. – Pikoh Nov 03 '16 at 11:19
  • @Pikoh you are absolutely correct, however i have 30 projects in my solution. refactoring this would take time, I have taken example of two project in my question to make it simple.. – Manish Makkad Nov 03 '16 at 11:20
  • 3
    _refactoring this would take time_ - this the reason why you get in this situation – Fabio Nov 03 '16 at 11:21
  • I don't think this would take a lot of time, and i think that's the best solution... – Pikoh Nov 03 '16 at 11:22
  • 2
    ask architect who played with you :) – A.T. Nov 03 '16 at 11:22
  • @Fabio Sorry but i have tight deadline and refactoring could be done only after that.. – Manish Makkad Nov 03 '16 at 11:22
  • 1
    If you will use some "hacky" workaround for this problem, then later you will face another more complex problem where you again need to think about some workarounds. – Fabio Nov 03 '16 at 11:23
  • 1
    First law of software engineering: _could be done only after that_ = never be done – Fabio Nov 03 '16 at 11:24

2 Answers2

4

It is not possible and will require refactoring in perhaps one of these directions:

  • Merge the two projects that 'need to reference each other' into one bigger project. Possible disadvantage: a huge project that contains too much, or has too many responsibilities, or mixing of layers (e.g. DAL, BL). Especially if it concerns more than 2 projects to begin with.
  • Move conflicting parts out of proj1, 2 ... n, and into new projX. Then reference projX from proj1, 2 ... n.
  • Identify interfaces, and put them somewhere central like projX again. Make everything (or the conflicting items) in proj1, 2 ... n inherit from the interfaces. Pass objects around using interface types instead of object types.
Peter B
  • 22,460
  • 5
  • 32
  • 69
0

The key to your solution is within this: due to circular reference issue this means that you should separate logic to a third assembly, so you can add the references.

Jeroen van Langen
  • 21,446
  • 3
  • 42
  • 57