
Master the ASP.NET Core dependency injection container by registering, injecting, and resolving services at runtime, and explore service lifetimes to build efficient, testable applications.
Explore the theory behind dependency inversion, dependency injection, and IOC containers, clarifying how abstractions and details relate, and how inversion of control enables these patterns and frameworks in applications.
Explore a dotnet 5 microservice project to teach dependency injection and service lifetimes, featuring product and sourcing web APIs with MongoDB, SignalR, MsSql Server, Ocelot api gateway, RabbitMQ, and frontend.
Learn why dependency injection and inversion of control matter in ASP.NET Core, using the DI container to decouple concrete services like mail sending and improve testability.
learn how dependency inversion and abstractions drive dependency injection by extracting an interface for the mail sender and wiring it in startup to decouple the controller from concrete providers.
The lecture demonstrates constructor injection by injecting IMailSenderService into HomeController via the constructor, using a private readonly field, avoiding new, and troubleshooting container resolution.
Register the first service by defining IMailSenderService and MailSenderService in the Startup.ConfigureServices method, using constructor injection and a transient lifetime to resolve via the dependency injection container.
Discover how dependency injection boosts sustainability, testability, readability, extensibility, and flexibility, enabling easy replacement of services like mail providers through interfaces and constructor injection with mock-based testing.
Explore how the Microsoft dependency injection container underpins ASP.NET Core, registering services with IServiceCollection in startup and resolving them via IServiceProvider during http requests, including transient, scoped, and singleton lifetimes.
Learn how to access appsettings.json configuration in ASP.NET Core using the options pattern and dependency injection, wiring mail settings via MailSettings and using From and To in the mail sender.
Explain how the dependency injection container manages lifetimes—transient, scoped, and singleton—and illustrate with a GUID service and startup registrations to show creation and reuse behavior.
Transient services are recreated per http request, not necessarily thread-safe, avoiding sharing but increasing memory usage; use them when unsure which lifetime fits best, as shown in the middleware example.
Explore singleton lifetime in dependency injection: a single instance is created on first request and reused across subsequent requests, with memory, thread-safety, and potential leak considerations.
Explore the scope lifetime in ASP.NET Core, where a new instance is created per HTTP request and reused within the same scope, highlighting the need for thread-safe scoped services.
Learn how ASP.NET Core handles transient, scoped, and singleton lifetimes and why longer-lived services must not depend on shorter-lived ones to prevent memory leaks; enable validate scopes in development.
Explore how add versus TryAdd affects multiple registrations of the same IMailSenderService, showing that TryAdd prevents duplicates and ensures the first registered service remains, improving security and validation.
We replace and remove registered services in the dependency injection container using Replace and RemoveAll, switching IMailSenderService to XMailSenderService and removing all records.
Use implementation factories to configure services at resolve time in asp net core dependency injection, driven by configuration. Wire dependencies like sourcing context and rabbitmq publishers via the service provider.
Register open generic services in the dependency injection container using a generic repository pattern to enable CRUD across entities, illustrated with the order microservice, IRepository, and OrderRepository.
Register application and infrastructure services with extension methods on IServiceCollection to simplify ConfigureServices, embrace the fluent design pattern, and keep startup clean within clean code architecture.
Explore ASP.NET Core service resolution mechanisms, focusing on two approaches: IServiceProvider and ActivatorUtilities, and how they resolve services, constructors, and framework components.
Explore constructor injection in ASP.NET Core, learn rules for public constructors, and how ActivatorUtilities and IServiceProvider resolve constructors for controllers, middleware, and other components.
Action injection demonstrates resolving services only for specific actions, not the constructor, using the FromService attribute to inject MailSender into SendMail while keeping index, privacy, and error actions lean.
Learn how to inject services into middleware using dependency injection, handle singleton, scoped, and transient lifetimes, and use constructor versus Invoke methods to avoid lifetime errors.
Discover view injection in ASP.NET Core by injecting configuration data and services into Razor views with the inject keyword, and rendering UI elements based on available settings and Guid service.
apply automatic migrations with a migrations database extension in ASP.NET Core, creating a scope from the service provider to resolve and seed the order context during startup.
Hasan Denli wraps up the training, hoping you gained useful information and can apply the knowledge in your life applications. BestCodder and Ertuğrul Yılmaz invite you to the next training.
Concepts such as Dependency Inversion, Inversion Of Control, IOC Container, Dependency Injection are very important but confusing concepts while developing code in today's world. In this course, we will define these concepts. We will describe the Microsoft Dependency Injection Container, which comes as Fundementals in ASP NET CORE Framework and forms the basis of almost all components, with all its features. In this way, you will be able to increase the quality of your applications by developing more efficient, sustainable, testable and lavishly coupled applications by using this information while developing code in daily life.
What is Dependency Inversion Principle?
What is Inversion Of Control Principle (IOC)?
What is Dependency Injection Design Pattern?
Why do we use Dependency Injection Container?
What are the benefits of Dependency Injection Container?
What architectural problems will we encounter if we do not use a Dependency Injection Container? What are the disadvantages of these problems? How does the Dependency Injection Container solve these problems?
What is Dependency? How do we detect dependencies?
What are Service Lifetimes? How do we manage relationships between each other?
When to use Transient, Scoped, Singleton Lifetimes?
While answering questions such as;
We will learn the end-to-end use of Microsoft Dependency Injection Container by making examples about Microsoft Dependency Injection Extension methods and their uses, and solutions to more complex problems through the Microservice architecture training project. We will also have a few examples on how you can develop Clean Code using Dependency Injection.
Our expectation is not that you develop in parallel while following the training, but that you understand the scenarios, concepts and what we do and why we do it. We shared all the projects used in education as open source code. In this way, you can test the codes described in the training yourself and reinforce what you learned in the training.
If you want to concat to us => bestcodderacademy@outlook.com