0

Suppose I have the following structure in my C# solution:

ServiceProject
-- IBusinessLogic.cs
-- Service.cs

BusinessLogicProject
-- IRepository.cs
-- BusinessLogic.cs

RepositoryProject
-- Repository.cs

In this case, I have BusinessLogicProject references ServiceProject (because BusinessLogic implements IBusinessLogic) and RepositoryProject references BusinessLogic (for a similar reason).

Suppose that I want to add StructureMap and use IoC container to register types and classes. It appears to me that this container will depend on interfaces--and hence should reference those projects, and it appears that all the projects need to reference this container--hence every project will depend on the container. How can I change this structure without introducing circular dependency?

Husain
  • 784
  • 1
  • 9
  • 22
  • Why would all project reference the container? – Yacoub Massad Mar 14 '16 at 13:34
  • To resolve the types? The BusinessLogic will need a repository. So it will need the container to resolve the type of the repository it needs. Is there a way to hide that? – Husain Mar 14 '16 at 13:37
  • 5
    If your classes depend on the container to resolve a dependency, you're misapplying the IoC principle. It sounds like you're using the Service Locator anti-pattern. Your classes should receive their dependencies via constructor injection, and your composition root should be responsible for managing the dependency chain. – Yannick Meeus Mar 14 '16 at 13:48

0 Answers0