Junior — Middle
What types of dependency registration are you familiar with in an IoC container?
sobes.tech AI
Answer from AI
The following dependency registration types are commonly used in IoC containers:
- Singleton — one instance of the object is created for the entire application lifecycle, and this same instance is used for every request.
- Transient — a new instance of the object is created for each request.
- Scoped — an instance is created once within a specific scope (e.g., within a single HTTP request) and reused within that scope.
Example registration in C# using Microsoft.Extensions.DependencyInjection:
services.AddSingleton<IMyService, MyService>();
services.AddTransient<IMyService, MyService>();
services.AddScoped<IMyService, MyService>();