Given a code project which is supposed to adhere to the SoC principle by implementing loosely coupled layers, having an IoC container, etc., for example, a simple ASP.NET MVC solution which is separated into the following assemblies:
- Application assembly+namespace
- Model assembly+namespace (contains a concrete repository to access DB data)
and where a concrete repository in the Model assembly must implement a common interface IMyBusinessRepository
, in which assembly would you put that interface?
1) If you put that interface in the Model assembly, chances are that it would be impossible to replace that assembly by another one (at least if it has a different namespacing) without modifying the code of the Application assembly. Also, an alternative IMyBusinessRepository
implementation residing in a different assembly would have to reference the original one (Argh!)
2) If you put it in the Application assembly, it would be impossible to use the Model assembly in other projects without referencing the Application assembly (Argh!)
3) Or would you create a separate common assembly just for that interface, and for that matter, for each common interface or set of interfaces? (Argh?)
To summarize, X assembly should be easily replaceable in application A (merely by changing a reference), and reusable in applications B, C, D.
Option 3.
Putting the interface definitions in with the calling code is fine right up until you want to develop against the interfaces but not the component that's holding it (say you want to build a data access provider but you don't want to pull in the whole website project). Putting it with an implementation is just crazy talk :)
I would group interfaces into separate assemblies by thinking about the Commom Closure and Common Reuse principles. By being on their own they will also be more stable. Think about the scenarios in which they will be used - does keeping them together make sense - if so then they are probably OK in one assembly.