Why one module per assembly?

Topics: Prism v2 - WPF 3.5
Mar 30, 2010 at 9:02 AM
Edited Mar 30, 2010 at 9:22 AM

Hi All,

Firstly, lets agree on definitions:

  • My definition of assembly is based on the book "CLR via Csharp, 3rd edition" by Jeffrey Richter:

"To summarize, an assembly is a unit of reuse, versioning, and security  It allows you
to partition your types and resources into separate fles so that you, and consumers of your assembly, get to determine which fles to package together and deploy  Once the CLR loads the fle
containing the manifest, it can determine which of the assembly’s other fles contain the types and
resources the application is referencing  Anyone consuming the assembly is required to know only
the name of the fle containing the manifest; the fle partitioning is then abstracted away from the
consumer and can change in the future without breaking the application’s behavior
If you have multiple types that can share a single version number and security settings, it is 
recommended that you place all of the types in a single fle rather than spread the types out 
over separate fles, let alone separate assemblies  The reason is performance  Loading a 
fle/assembly takes the CLR and Windows time to fnd the assembly, load it, and initialize it  
The fewer fles/assemblies loaded the better, because loading fewer assemblies helps reduce
working set and also reduces fragmentation of a process’s address space  Finally, nGen exe 
can perform better optimizations when processing larger fles"

In short assembly is a physical unit of reuse.

  • Definition of module is from "Composite Application Guidance for WPF and Silverlight" - October 2009:

"A module in the Composite Application Library is a logical unit in your application."

I'm developing an application based on Prism V2 - WPF. Suddenly in the middle of the project I realized that deployment structure of the project becomes too complex about 10 different assemblies is used to deploy application(8 of them are modules).

So my question is:

For what reason the guidance recommends to use one module per assembly ? (at least it used in for reference implementation).

I'm wondering why there is an indirect recommendation to mix physical and logical units of application or I misunderstood something?

Thanks in advance for answering and taking the time to read the post,

Yours sincerely,

Maxim Filimonov

Mar 30, 2010 at 4:21 PM

Hi Maxim,

Some of the benefits that lead from developing modules in separate assemblies are:

  • It contributes to decoupling, as it avoids the possibility of executing code of a module directly from another one.
  • It makes it possible for different teams to work on different modules, make modifications and recompile each module without affecting the others.
  • It allows reusing a module in another application without having to load the entire assembly with other modules that the other application may not need.

However, if you consider putting several modules in the same assembly better suits your application’s needs, Prism allows you to do it.

I hope you find this helpful.

Guido Leandro Maliandi