Michael
Michael

Reputation: 3150

Are there any hacks to resolve circular reference problems?

I inherited a code base that wasn't well thought out, and am running into some circular reference problems. My team doesn't currently have the time or resources to do a huge refactor, so I was wondering if there was some switch that I could flip that says "build these two dlls atomically."

A simplified example:

DLL D0:
    class A1 -> References B1
    class B1 -> References A1

Class A1 and B1 have references to each other, and as they're in the same DLL, this is fine - but they don't have much in common so I want to break them out into separate dlls.

However, the following is impossible because of a circular reference problem:

DLL D1: class A1 -> References D2.B1
DLL D2: class B1 -> References D1.A1

I want to be able to tell MSBuild to build (D1+D2) as if all of the code were in a single dll. Is there anything I can do here or do I follow SOP and "hack it in?"

Disclaimer: I understand this implies I have a much bigger problem with my model (the most glaring is an improper use of interfaces), but in the small company, real world scenarios dictate that I bend over backwards to fix production bugs at the expense of best practices.

Upvotes: 5

Views: 189

Answers (1)

Paul Sasik
Paul Sasik

Reputation: 81479

My team doesn't currently have the time or resources to do a huge refactor

so... DO NOT DO THIS:

but they don't have much in common so I want to break them out into separate dlls.

Leave it alone until you can apply significant refactoring to the whole solution.

This is a case where refactoring an organizational peeve will force a huge amount of refactoring down stream. And you have much bigger problems to deal with. I've been there. I feel for you. Good luck mate.

Upvotes: 12

Related Questions