views:

228

answers:

4

I like the idea of having Interfaces and Implementation separate. But how separate? Are the Interface definitions in a separate .Net assembly? Do you have a single project that defines all Interfaces for a solution? Otherwise are there issues with circular dependencies of Interfaces?

+7  A: 

Put your domain objects and interfaces in a seperate "domain" assembly.
This assembly should never reference anything but the core .net assemblies.

This way you get a clean seperation from your domain/service model and your implementation.

Edit:
http://jeffreypalermo.com/blog/the-onion-architecture-part-1/

Lars Mæhlum
Thought it worth including a link to Jeffery Palermo's excellent article on the Onion architecture http://jeffreypalermo.com/blog/the-onion-architecture-part-1/
David Hall
Thanks. This article explains the concept very well.
Lars Mæhlum
+3  A: 

I wouldn't put the interfaces into a separate assembly just for the sake of it. However, if the interfaces take part in any form of IPC or extensibility architecture then it often makes sense to give them their own assembly.

If you have projects that need to reference each other, then yes, you will need a separate assembly for the interfaces, but you should also carefully examine architecture to see if there is another way of resolving the circular dependency.

Rob Walker
+1  A: 

I prefer keeping the most common or simple implementations of the interface in a sub-folder (and namespace) following the name of the interface.

\project\
\project\IAppender.cs
\project\Appender\
\project\Appender\FileAppender.cs
\project\Appender\ConsoleAppender.cs

If I extend this class outside the project. In a special project, repeat the folders/namespace similarly.

\specialproject\
\specialproject\Appender\
\specialproject\Appender\MemoryAppender.cs
Anthony Mastrean
A: 

In the project I'm working on right now, the interfaces and related base classes go into assemblies that are logically divided among functions. The implementations of these providers and classes go inside a core assembly. The idea being that people who use our API can reference more or one of the API dlls in a clear and logical manner.

Smaller applications don't need this kind of separation. But, no matter where I keep the interfaces, I would keep them in the same namespace as any base classes.

Will