Here's the setup I have in a vs2008 solution:
Data layer in a project named MyProject.Data
Web application in a project named MyProject.Web
MyProject.Web has a reference to MyProject.Data
In MyProject.Web I have a class I use called "MySite.Utils"
I want to be able to use MySite.Utils in MyProject.Data but I can't because it would cause a circular reference.
One solution which is NOT possible is creating a third project and moving "MySite.Utils" in there because MySite.Utils actually uses MyProject.Data (thus it needs to reference it and another circular reference would be created)
What's the best/easiest way to fix this?
You need to move MySite.Utils to MyProject.Data by the sound of it
The best fix is to simplify things... for example, is that utility code data utility code, or ui utility code. Perhaps split it into 2 dlls; that might make things simpler.
After that, interfaces are a reasonable option, but you might need some IoC framework to provide the implementations. IoC is the most common way of getting around this type of problem. For example, you declare your ICustomerRepository in a reference assembly; everything references that. Your DAL implements the interface, but the utils project no longer needs to reference the DAL - just the interface assembly. Your DAL can now reference the utils - or it might just know about another interface IDataUtils (better to split it up more meaningfully, of course). The glue here is the IoC container, such as Castle Windsor.
Finally, and don't do this, but even though the IDE doesn't let you, it is possible to create circular references in .NET (via the command line tools); it is legal, but it gets very messy very quickly, and it is hard to repair a broken build. Don't go there!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With