views:

102

answers:

4

How should I divide source files into projects (within one solution) to

  1. be able to use common classes in more relatively independent apps,
  2. avoid lots of dlls needed (preferably all in one file for each application),
  3. keep it fast?

There are working (data processing) classes, User controls, some utility classes and Forms of the application.

+5  A: 

You can make a separate assembly by creating a class library, and use that library within other projects within your solution. Just put your reusable classes within a class library project, and add a project reference in your applications to that library.

Each time you separate out code into a separate (reusable) assembly, it does add one extra DLL (the class library project) as a requirement at runtime, but this is very minimal.

There are no real (significant) changes to performance when doing this. It is a very common practice.

Reed Copsey
A: 

You could put the common classes into one assembly (say CommonUtils) and then use namespaces inside for the groupings to indicate how they are split

Preet Sangha
+1  A: 

You should make Class Library project(s) for each logical unit of classes, then add references to the libraries in each project that uses them.

For example, you could have a Common library that contains basic classes used by everything else, and perhaps a Controls library that contains user controls.

Each logical unit of classes can go in a namespace within the same library or in a separate library; you need to decide which.

SLaks
+1  A: 

It would be a good idea to drop the second requirement of avoiding lots of DLL's. If you put your common code into a single "common" DLL then you need to recompile every time any class is added or modified. This could then give you a terrible versioning problem that is worse than managing lots of DLL's.

You should group your common code, by the functionality they provide, into separate DLL's. So one for data access, one for user controls, one for each type of utility function, etc. Then if you have web service that accesses data you won't need to recompile the service when you add a new user control to a single DLL. Only those apps that depend on the change will need to be recompiled.

Enigmativity
The thing I really care about is not the number of files, but the speed (both in VS navigation/building and especially runtime)
Lukas
@Lukas - Loading of DLL's aren't really that time consuming in comparison to JIT'ing of the classes that you are running. Remember that only the code that needs to get run is actually JIT'ed, but if you have a lot of code in one method then it can take a long, long time to JIT - far longer than loading the assembly. So if you reference 100 assemblies but only execute code from one of them then 99 assemblies aren't loaded and only the code that is actually executed from the one assembly is JIT'ed.
Enigmativity