| 1. |
Explain how dependency injection works in ASP.NET Core? |
|
Answer» ASP.NET Core injects instances of dependency CLASSES by using the built-in IoC (Inversion-of-Control) container. This container is represented by the IServiceProvider interface that supports constructor injection. The types (classes) managed by the container are called services. To let the IoC container automatically inject our services, we first need to register them with the IoC container in the Startup class. ASP.NET Core supports two types of services, namely FRAMEWORK and application services. Framework services are a PART of ASP.NET Core framework such as ILoggerFactory, IApplicationBuilder, IHostingEnvironment, etc. In contrast, a developer creates the application services (custom types or classes) SPECIFICALLY for the application. |
|