我一直在阅读有关如何使用ServiceStack的Redis客户端的一些文档和文章,但是它们都使用ServiceStack的AppHost
方法及其内置的Func IOC
但是我不想在我的项目中混合使用不同的IOC容器。
此外,除了Redis客户端,我不想使用任何其他ServiceStack组件。因此,我想最好通过IRedisClientsManager
工厂注入(inject)RedisManagerPool
的单例实例,直接从 Startup.cs的ConfigureServices
方法开始。
最佳答案
查看更新后的.NET Core Live Demos中的代码后
我想出了一种干净简单的方法。
所以在我的ConfigureServices
方法中,我像这样注册了IRedisClientsManager
services.AddSingleton<IRedisClientsManager> (c =>
new RedisManagerPool(Configuration.GetSection("Redis-Host").Value));
当然,为了从ConfigureServices中的配置中读取信息,您需要添加一个构造函数以将其注入(inject)到Startup中
IConfiguration Configuration { get; set; }
public Startup(IConfiguration configuration) => Configuration = configuration;
关于asp.net-core - 如何:使用默认容器在ASP.NET Core中注册ServiceStack的Redis Client Manager单例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50142272/