I have a solution that has an MVC3 web front end. I have a separate assembly for view models. I have a Services assembly that contains all domain objects and business functionality and business validation. My Service also provides all view models to my web site. So the website is aware of the Service and Model assemblies. The Service is aware of the Models assembly only, and the Model assembly isn’t aware of either.
So I have a case where I need the Service to validate and process a Cart model. The items in the cart implement an interface, that I would like defined in the Service assembly. My problem is that in order for my Cart Model to use this interface, it needs to know about the Service assembly. If I define the interface in my Models assembly, I’ve now coupled these two assemblies together in a way I don’t want.
So I decided I could decouple these by adding another assembly that contains the interface, and each would reference it. So, now they would both be tightly coupled to this assembly, but they are not coupled directly too each other.
Is this ‘Interface only’ assembly a viable solution or should I be doing things differently?
You can either put the Cart’s interface in the Model assembly (where the Service assembly could also see it), or you could put it in a 4th, “interface only” assembly. If you go with the latter, you might want to consider making your MVC project and service project only reference the new assembly, since that would have the added benefit of reducing coupling to the model implementations in the model assembly.
EDIT: I should mention that removing the dependency on the Model assembly and only referencing an interface-only assembly would require using an IoC container or something similar to load the concrete implementation (defined in the Model assembly)