Skip to content

AddEasyCaching access to IServiceProvider - Redis Services are resolved at runtime via another Service  #273

Open
@Simonl9l

Description

@Simonl9l

Hi - We're trying to use the caching in an environment were the Redis endpoints are discoverable via a service registry (consul). It would be great if the AddEasyCaching configuration action had access to the service provider.

Do you have any recommendation to best active this with what is available today, given that the service (per RedisEndpoints) below is registered elsewhere, and it being not best practice to cal' BuildServiceProvider() directly.

The EF Core DBContext AddDBContext service extension for configuration as an example does provide access to the service provider,

It would be great if in future versions I could do something like the following:

 services.AddEasyCaching((serviceProvider, option) =>
{
    option.UseRedis(config =>
    {
        config.DBConfig.AllowAdmin = true;
        serviceProvider.GetRequiredService<RedisEndpoints>().ForEach(endpoint => config.DBConfig.Endpoints.Add(new ServerEndPoint(endpoint.Host, endpoint.Port)));
    }, providerName);
});
  • Provider : Redis (version 1.1.0)
  • Interceptor : Asp Net Core (version 3.1.400)
  • Serializer : not use
  • System : alpine

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions