Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redis ServiceStack';s iDisclientManager+;Ninject-是否使用InSingletonScope?_Redis_Ninject_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">servicestack - Fatal编程技术网 servicestack,Redis,Ninject,servicestack" /> servicestack,Redis,Ninject,servicestack" />

Redis ServiceStack';s iDisclientManager+;Ninject-是否使用InSingletonScope?

Redis ServiceStack';s iDisclientManager+;Ninject-是否使用InSingletonScope?,redis,ninject,servicestack,Redis,Ninject,servicestack,我有一个ASP.NET MVC应用程序,在其中我刚刚开始使用ServiceStack的Redis客户端。我使用Ninject作为IoC容器。当前我的绑定如下所示: Bind<IRedisClientsManager>() .ToMethod(c => new BasicRedisClientManager("localhost:6379")) .InSingletonScope(); Bind<ICacheClient>().ToMethod(c

我有一个ASP.NET MVC应用程序,在其中我刚刚开始使用ServiceStack的Redis客户端。我使用Ninject作为IoC容器。当前我的绑定如下所示:

Bind<IRedisClientsManager>()
    .ToMethod(c => new BasicRedisClientManager("localhost:6379"))
    .InSingletonScope();

Bind<ICacheClient>().ToMethod(c => c.Kernel.Get<IRedisClientsManager>().GetCacheClient());
Bind<IRedisClient>().ToMethod(c => c.Kernel.Get<IRedisClientsManager>().GetClient());
Bind()
.ToMethod(c=>新的BasicRedisClientManager(“localhost:6379”))
.InSingletonScope();
Bind().ToMethod(c=>c.Kernel.Get().GetCacheClient());
Bind().ToMethod(c=>c.Kernel.Get().GetClient());

我在应用程序启动时有效地创建了一个BasicRedisClient Manager的单例实例,用于在任何对ICacheClient或IRedisClient的请求中进行实例化。我在这里所做的对于典型用例正确吗?提前谢谢

是的,BasicRedisClientManagerPooledRedisClientManager都是线程安全的,设计为作为单例使用。2之间的区别在于BasicRedisClientManager每次返回时都会创建一个新连接,而PooledRedisClientManager会维护一个打开的Redis连接池。

谢谢!我现在正在重新考虑我上面的另一个绑定。具体地说,IRedisClient被注入到控制器中,在gc通过之前它一直挂在那里。这类似于保持关键资源的开放吗?保持它们的短暂性(即将它们的创作包装在using语句中)重要吗