Files
Yi.Admin/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/CacheExtension.cs
2022-10-26 20:01:18 +08:00

35 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}
}