我一直在阅读有关如何使用ServiceStack的Redis客户端的几篇文档和文章,但他们都使用ServiceStack的AppHost
方法及其内置的Func IOC
但我不想在我的项目中混合使用不同的IOC容器。
此外,我不想使用Redis客户端以外的任何其他ServiceStack组件。因此,我想直接从<{>> Startup.cs
IRedisClientsManager
方法通过RedisManagerPool
工厂注入ConfigureServices
的单例实例
答案 0 :(得分:2)
在审核了更新后的.NET Core Live Demos代码后 我想出了一个干净简单的方法。
因此,在ConfigureServices
方法中,我注册了IRedisClientsManager
这样的
services.AddSingleton<IRedisClientsManager> (c =>
new RedisManagerPool(Configuration.GetSection("Redis-Host").Value));
当然为了从ConfigureServices中的配置中读取,您需要添加一个构造函数以将其注入Startup
IConfiguration Configuration { get; set; }
public Startup(IConfiguration configuration) => Configuration = configuration;