using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Ropin.Core.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ropin.Core.Extensions
{
///
/// Memory缓存 启动服务
///
public static class MemoryCacheSetup
{
public static void AddMemoryCacheSetup(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddScoped();
services.AddSingleton(factory =>
{
var value = factory.GetRequiredService>();
var cache = new MemoryCache(value);
return cache;
});
}
}
}