ardalis / ddd-guestbook

A DDD guestbook example written for ASP.NET Core
MIT License
691 stars 146 forks source link

Removing reference to Infra project in Web Project #5

Closed funzeye closed 6 years ago

funzeye commented 6 years ago

I notice you have added, and are referencing, the Infrastructure layer in your UI layer (in startup.cs) for DI purposes.

Can you recommend any ways in which to remove this dependency? (Apart from using StructureMap!)

I have been reading about creating a factory in the Core layer to accomplish this?

Only problem I see with using the 'factory in Core' approach is that I would need to reference the Infrastructure layer in the core layer to do this, removing the core reference in the infrastructure project ( to avoid circular dependency) which completely changes the role of the Core project (not really "central" anymore, just a middle layer).

ardalis commented 6 years ago

I would avoid putting anything in Core that would require a reference to Infrastructure. In fact this will be impossible to do at compile time due to the circular dependency as you noted. I have an article on accomplishing what you're looking for here: https://ardalis.com/avoid-referencing-infrastructure-in-visual-studio-solutions

I haven't updated it yet for .NET Core, partly because .NET Core doesn't make it easy to configure EF Core outside of Startup (in the web project). However, looking at the technique used in that article might give you some ideas, and it's on my backlog to get it working in an ASP.NET Core solution and write another article... Let me know if you figure something out that works well.