# Dependency Injection

## Register all the needed part into your DI container

Becoming a super hero is a fairly straight forward process and one step of this process is to use a dependency injection container.

All you need to do is this:

```javascript
/// <summary>
/// Add StackExchange.Redis with its serialization provider.
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="redisConfiguration">The redis configration.</param>
/// <typeparam name="T">The typof of serializer. <see cref="ISerializer" />.</typeparam>
public static IServiceCollection AddStackExchangeRedisExtensions<T>(this IServiceCollection services, RedisConfiguration redisConfiguration)
    where T : class, ISerializer, new()
{
    services.AddSingleton<IRedisCacheClient, RedisCacheClient>();
    services.AddSingleton<IRedisCacheConnectionPoolManager, RedisCacheConnectionPoolManager>();
    services.AddSingleton<ISerializer, T>();

    services.AddSingleton((provider) =>
    {
        return provider.GetRequiredService<IRedisCacheClient>().GetDbFromConfiguration();
    });

    services.AddSingleton(redisConfiguration);

    return services;
}
```

There are two important things to know in this code block:

* Ho to retrieve an instance of the redis configuration ([here](/stackexchange-redis-extensions/configuration.md) the solution);
* Choise the right serializer ([here](/stackexchange-redis-extensions/serializers.md) few options)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://imperugo.gitbook.io/stackexchange-redis-extensions/dependency-injection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
