1. Junior

    How do the Transient, Scoped, and Singleton service lifetimes differ in .NET?

    Transient creates a new instance on each injection, Scoped creates one instance per HTTP request shared by its components, and Singleton creates one instance shared for the process lifetime.

    Read the full explanation
  2. Senior

    What is Captive Dependency in the .NET DI container, and how do you detect and prevent it?

    It happens when a shorter-lived service (such as Scoped) is injected into a longer-lived service (such as Singleton), keeping the Scoped instance in memory forever and preventing cleanup.

    Read the full explanation
  3. Mid-level

    How do Keyed Services added in .NET 8 work, and how do they address multiple implementations?

    They let you register multiple implementations of the same interface with explicit keys and request a specific one with [FromKeyedServices("key")] without a custom factory.

    Read the full explanation
  4. Mid-level

    Who calls Dispose() on services implementing IDisposable when using the .NET DI container?

    The DI container is responsible for automatically calling Dispose() on services it creates when their Scope ends or when the application shuts down for Singletons.

    Read the full explanation
  5. Senior

    How does Scrutor use Assembly Scanning to register services automatically with Convention-over-Configuration?

    It scans project classes and registers those implementing matching interfaces with specified lifetimes in one line, instead of writing hundreds of AddScoped calls manually.

    Read the full explanation
  6. Mid-level

    Why is the Service Locator pattern (injecting IServiceProvider directly) an Anti-pattern in C#?

    It hides a class's real dependencies, bypasses static compiler checks, complicates unit testing, and can cause runtime errors when requested services are not registered.

    Read the full explanation
  7. Senior

    How do you register and resolve Open Generics such as IRepository<> in the .NET container?

    Register the open interface type and open implementation without specifying a type argument, with typeof(IRepository<>) and typeof(Repository<>), so the container can construct closed types automatically.

    Read the full explanation
  8. Junior

    What does the [FromServices] Attribute do, and when would you inject a service into an Action method instead of the constructor?

    It injects a dependency directly into a specific Action method parameter; prefer it for an expensive service used only on one route and not elsewhere in the Controller.

    Read the full explanation
  9. Mid-level

    What happens when multiple classes implementing the same interface are registered in the .NET container, and how do you resolve them all?

    Resolving one IService returns only the last registered class, while injecting IEnumerable<IService> returns every registered implementation in order.

    Read the full explanation
  10. Senior

    When should you replace .NET's built-in container with an advanced container such as Autofac?

    When you need advanced features that are not supported natively, such as Property Injection, Interception for aspect-oriented programming (AOP), or complex custom scopes.

    Read the full explanation