-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathServiceCollectionExtensions.cs
37 lines (31 loc) · 1.48 KB
/
ServiceCollectionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddOidcCache(this IServiceCollection services, IConfiguration configuration)
{
var options = configuration.GetSection("RedisConfig").Get<RedisConfigurationOptions>();
services.AddOidcCache(options);
return services;
}
public static IServiceCollection AddOidcCache(this IServiceCollection services, RedisConfigurationOptions options)
{
services.AddMultilevelCache(
Constants.DEFAULT_CLIENT_NAME,
distributedCacheOptions => distributedCacheOptions.UseStackExchangeRedisCache(options),
multilevelCacheOptions =>
{
multilevelCacheOptions.SubscribeKeyType = SubscribeKeyType.SpecificPrefix;
multilevelCacheOptions.SubscribeKeyPrefix = Constants.DEFAULT_SUBSCRIBE_KEY_PREFIX;
}
);
services.AddSingleton<MemoryCacheProvider>();
services.AddSingleton<IClientCache, ClientCache>();
services.AddSingleton<IApiScopeCache, ApiScopeCache>();
services.AddSingleton<IApiResourceCache, ApiResourceCache>();
services.AddSingleton<IIdentityResourceCache, IdentityResourceCache>();
return services;
}
}