jasontaylordev / CleanArchitecture

Clean Architecture Solution Template for ASP.NET Core
MIT License
16.58k stars 3.56k forks source link

What is the purpose of class DependencyInjection in the Clean Architecture template project? #55

Closed grassit closed 4 years ago

grassit commented 4 years ago

In https://github.com/JasonGT/CleanArchitecture, Startup.ConfigureServices() in src/WebUI/Startup.cs registers services for dependency injection.

AddInfrastructure() in src/Infrastructure/DependencyInjection.cs also registers services. But is it correct that class DependencyInjection and method AddInfrastructure() are not used in any other files? What are their purposes?

Putting services.AddContextDb() in DependencyInjection.AddInfrastructure() may have caused definition of 'UseSqlite' not found in https://github.com/JasonGT/CleanArchitecture/issues/52

Thanks.

tomfroehle commented 4 years ago

The method AddInfrastructure is used in the Startup.ConfigureServices(): https://github.com/JasonGT/CleanArchitecture/blob/c1c3c97c0d105655b04e9023af7ac076a7b7f6a5/src/WebUI/Startup.cs#L37

The purpose of the DependencyInjection class in the Infrastructure project as I understood is to encapsulate the dependencies of one project in a single call (e.g. AddApplication, AddInfrastructure). Jason talks about this in his talk: https://youtu.be/5OtUm1BLmG0?t=1663

jasontaylordev commented 4 years ago

This is correct, I think it is a nice and simple approach to managing dependencies across layers using the built-in .NET Core DI.