My solution has 4 projects in it
- UI
- Infrastructure
- Entities
- Tests
All of the code-first database setup and the structuremap setup sits within the infrastructure project. The UI is ASP.NET MVC5. The infrastructure project also hosts some WebService implementations.
In the UI Project has some classes which act as a layer between the Controllers and the External WebServices. For example:
UI.Services.MappingService.cs
will be using methods in Infrastructure.ExternalWebServices.MappingWebService.cs
Until now there has been no problems, the interface names all match the concrete class names, so structuremap resolves them correctly. However, there is now a requirement to make changes and implement multiple concrete classes from one of the service interfaces.
The infrastructure project cannot reference the UI as it creates a circular dependency. Using the Mapping example, I would need
UI.Services.Interfaces.IMappingService
to have different concretes, structuremap would resolve the correct one either by logic in a Registry file or a factory class. The problem being the registry files are in the infrastructure project which is not aware of the UI so For(...).Use(...)
is not possible.
If I move the Interfaces out to the Entities project, it can then see them but that would also involve moving the concrete classes out which would break many references and require a hell of a lot of moving files to fix. The entire service layer in UI plus quite a few view models would need to move out to the Entities project to make that possible.
Is there an easier way? I am no DI/StructureMap expert so I want to be sure I am not just making life harder.
Scan(x => x.AddAllTypesOf<IMappingService>())
. – Stuart Grassie