Reference from Web to Infrastructure only for AppDbContext
My goal is to remove the project reference from Web to Infrastructure but still have the solution load the AppDbContext when it starts up, is there already a solution for this in ASP.Net Core?
(https://stackoverflow.com/questions/46978844/how-to-use-structuremap-registry-to-configure-ef-core-in-separate-project)
I'm no expert on this, but I did look into doing something similar. Basically I had to use reflection to load the assembly file, then I registered that using my DI container. I would think you could do the same thing in asp.net core, and not register the db context using the built-in core DI container, similar to this:
https://stackoverflow.com/questions/181901/reflection-net-how-to-load-dependencies
Why would you want this though? The reality is that your application needs all those assemblies to function correctly so why would you try to hide this from all the tools that are there to help you? The dependency remains but it would only be discovered at runtime...
It really is not an issue the web project has a reference to infrastructure components as they are both frameworks/drivers.
@michjuh The reason you would want it is to avoid having team members (or those helpful tools) accidentally (or magically) pull in direct dependencies on infrastructure types instead of using abstractions to maintain loose coupling. It's not something I typically actually do in production, but it can be valuable for some teams and it can be a valuable exercise just to see if you can decouple your web project from your infrastructure. The harder it is, the more likely you have more coupling there than you probably should.