Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET solution - many projects vs one project

We currently have a rapidly growing C# codebase. Currently we have about 10 projects, split up in the usual categories, common/util stuff, network layer, database, ui components/controls etc.

We run into the occasional circular dependency where project x depends on something in y and vice-versa. We are looking at maybe collapsing the projects down to one and just managing using structure folders/namespaces. We have a Java project which of course organises just using folders/packages so we're not sure what, if any, benefit having multiple projects brings. None of our projects require special project properties, except the main run project, which we may kept separate (and very thin).

Does anyone have any prior experience in why one project is better/worse than multiple projects and could suggest the best approach? And also any issues with circular dependencies would be useful in either approach would be useful.

Any input appreciated.

like image 286
Mike Q Avatar asked Nov 06 '09 21:11

Mike Q


4 Answers

In my experience, separating code which creates a single executable in multiple projects can be useful if you want to

  • use different programming languages in different parts,
  • develop libraries that are also used by other applications, or
  • conceptually separate multiple layers (i.e., let Visual Studio ensure that there are no direct references from project Lib to project App).

Personally, I base most of my decisions on the second point. Do I think that part of the application can be a more general library that I am likely to need in other application? Put it in a separate project. Otherwise, as you point out, having a single project usually makes development easier.

About the circular dependencies: The recommended way to solve this is to put interfaces of the referenced stuff into a third project. For example, if you have two applications both sharing some objects through remoting, you put interfaces of the shared objects in a library project to ensure that they are available to both applications.

Without knowing the exact design of your application, it's difficult to give more concrete advise.

like image 97
Heinzi Avatar answered Nov 03 '22 01:11

Heinzi


If you've got projects with circular dependencies, that indicates a problem with the design of the code, not with the solution/project model.

like image 30
Jon Seigel Avatar answered Nov 03 '22 00:11

Jon Seigel


When making dependencies between projects, it helps to always think of one as "Lower" and the other as "Higher"

A higher level project (such as a web interface) should only depend on lower projects. A lower project (such as a utility) should never depend on something higher, such as a web interface. If this happens, it either means your higher level project has something that really should be in the lower project, or vice versa.

like image 31
Neil N Avatar answered Nov 03 '22 00:11

Neil N


Generally speaking, having multiple VS projects (within a VS solution) does just make sense in these cases

  • You can potentially reuse the produced DLL in another project (a class library)
  • You want to separate things like in a layered architecture where you may drop the DAO dll and exchange it with another
  • There are just different front-end projects (i.e. ASP.net MVC apps) which need to be deployed in different physical locations but use the same BL, DAL.

If your saying you're having the problem of circular dependencies, then you're having a problem in your code design. Probably you may put that logic which is used by multiple projects inside a class library designed to be reused in many projects.

Generally I'd say you shouldn't add more projects if you don't really need it. Splitting up into projects means adding more complexity, so when you're doing so, you should gain a reasonable benefit from it.

like image 38
Juri Avatar answered Nov 03 '22 01:11

Juri