I would like to set forth dependency mapping from a *.config file from a project that has no reference to the project that contains the concrete class.
I'll be using terms from C#, Microsoft Unity and Visual Studio: I've got a presentation layer with a web service project and a winform project, an infrastructure layer that communicates with repositories, and there is a core business logic layer that defines interfaces that the infrastructure must implement.
DIApplication.WebServices - references the Core + DependencyResolution projects
DIApplication.Winform - references the Core + DependencyResolution projects
DIApplication.Data - Communicates with repositories, references the Core
DIApplication.DependencyResolution - Registers to the dependencies from Core to Data projects. These are the only two projects it references
DIApplication.Core - Defines interfaces, references nothing
For an example I'll say I have DIApplication.Core.IRepository interface and DIApplication.Data.RepositoryA class and DIApplication.Data.RepositoryB class.
It's fine to say that the DependencyResolution project will register the dependencies:
//If Application == WebService container.RegisterType<IRepository , RepositoryA >(); //Else container.RegisterType<IRepository , RepositoryB >();
But what I would like to do is that the Webservices Web.config maps IRepository to RepositoryA, while the Winforms App.config maps IRepository to RepositoryB
< register type="DIApplication.Core.IRepository, DIApplication.Core" mapTo=" DIApplication.Data.RepositoryA, DIApplication.Data" />
< register type="DIApplication.Core.IRepository, DIApplication.Core" mapTo=" DIApplication.Data.RepositoryB, DIApplication.Data" />
The problem (I believe) is that neither DIapplication.Webservices or Winforms knows about DIapplication.Data, so it breaks on the final portion of this call in DIApplication.DependencyResolution:
IUnityContainer container = new UnityContainer(); UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); section.Configure(container);
With the error:
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Is there any way to get around this without having to include a reference to DIApplication.Data within both DIApplication.Webservices and Winforms?
Maybe I'm looking at this the wrong way. I know that it kind of breaks the notion of separation of concern, where the presentation layer shouldn't know nor care how data is being persisted to repositories, just that it is. But I also want to drive the dependencies based on what project is running.