mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-04 16:50:52 +08:00
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
|
|
using Microsoft.AspNetCore.Builder;
|
|||
|
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
|
using Microsoft.OpenApi.Models;
|
|||
|
|
using System;
|
|||
|
|
using System.IO;
|
|||
|
|
using Yi.Framework.Common.IOCOptions;
|
|||
|
|
using Yi.Framework.Core;
|
|||
|
|
using Yi.Framework.Core.Cache;
|
|||
|
|
|
|||
|
|
namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Redis扩展
|
|||
|
|
/// </summary>
|
|||
|
|
public static class CacheExtension
|
|||
|
|
{
|
|||
|
|
public static IServiceCollection AddCacheService(this IServiceCollection services)
|
|||
|
|
{
|
|||
|
|
var cacheSelect= Appsettings.app("CacheSelect");
|
|||
|
|
|
|||
|
|
switch (cacheSelect) {
|
|||
|
|
case "Redis":
|
|||
|
|
services.Configure<RedisConnOptions>(Appsettings.appConfiguration("RedisConnOptions"));
|
|||
|
|
services.AddSingleton<CacheInvoker, RedisCacheClient>();
|
|||
|
|
break;
|
|||
|
|
case "MemoryCache":
|
|||
|
|
services.AddSingleton<CacheInvoker, MemoryCacheClient>();
|
|||
|
|
break;
|
|||
|
|
default:throw new ArgumentException("CacheSelect配置填的是什么东西?俺不认得");
|
|||
|
|
}
|
|||
|
|
return services;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|