In der ConfigureServices-Methode Ihrer Startup-Klasse möchten Sie Folgendes hinzufügen:
services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect("yourConnectionString"));
Sie können dann die Abhängigkeitsinjektion verwenden, indem Sie Ihre Konstruktorsignatur wie folgt ändern:
public YourController : Controller
{
private readonly IConnectionMultiplexer _connectionMultiplexer;
public YourController(IConnectionMultiplexer multiplexer)
{
this._connectionMultiplexer = multiplexer;
}
}