'How to add to Services without a direct project reference - clean architecture?

I have 4 projects in my Clean Architecture solution:

  • Domain
  • Application
  • Infrastructure
  • Presentation.API

I have a method in each of these projects called Add{projectName} such as AddInfrastructure(services) which takes in IServiceCollection and wires up all it's classes.

My Presentation Layer has a project reference to Domain & Application however I want to call AddInfrastrcuture without having a project reference to my Infrastructure project.

I know a project reference is the easiest options however I don't want any of my Infrastrcutrue classes to be available in my Presentation layer. Is there anyway I can my infrastructure layer classes to my service collection without having to have a project reference? Something with reflection or assembly scanning?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source