C# 向SimpleInjector注册动态缓存

C# 向SimpleInjector注册动态缓存,c#,.net,dependency-injection,simple-injector,dynacache,C#,.net,Dependency Injection,Simple Injector,Dynacache,嗨,我试图在我的解决方案中使用缓存数据,我从数据库返回,所以当我使用Telerik grid过滤数据页等时,我不必每次都返回数据库获取数据 DynaCache页面上的示例显示它与Ninject DI一起使用,如下所示: kernel.Bind<IDynaCacheService>().To<MemoryCacheService>(); kernel.Bind<ITestClass>().To(Cacheable.CreateType<TestClass&

嗨,我试图在我的解决方案中使用缓存数据,我从数据库返回,所以当我使用Telerik grid过滤数据页等时,我不必每次都返回数据库获取数据

DynaCache页面上的示例显示它与Ninject DI一起使用,如下所示:

kernel.Bind<IDynaCacheService>().To<MemoryCacheService>();
kernel.Bind<ITestClass>().To(Cacheable.CreateType<TestClass>());
kernel.Bind().To();
kernel.Bind().To(Cacheable.CreateType());

我正在使用作为我的DI容器。是否有人将Dynacache与SimpleInjector一起使用,因为我在获得正确语法以使用SimpleInjector注册Dynacache时遇到了一些困难,正如Ninject中所示。Simple Injector的等价物是:

container.Register<IDynaCacheService, MemoryCacheService>();
container.Register(typeof(ITestClass), Cacheable.CreateType<TestClass>());
我现在已经准备好了一个涵盖这一点的例子——标记为正确的答案实际上并不正确——MemoryCacheService需要是一个单例,因为它包含一个需要在所有依赖实例之间共享的MemoryCache实例

container.Register<IDynaCacheService>(() => new MemoryCacheService());
container.Register(typeof(ITestClass), Cacheable.CreateType<TestClass>());