Reputation: 296
Replaced static SqlConnections with ISqlConnections abstraction, it is now theorically possible to use dynamic connection strings per request (multi tenancy++)
In Serenity .net 5 static SqlConnections was replaced with ISqlConnections abstraction, therefore the below line of code doesn't work.
Current Helper Method:
public bool SaveLoginLog(LoginLogRow logRow)
{
using (var connection = SqlConnections.NewFor<LoginLogRow>())
}
How would I be able to access a static instance of ISqlConnections within a helper class? Similar to the above snippet of code?
Upvotes: 0
Views: 270
Reputation: 88
You may declare a static class like the following
public static class AppStatics
{
public static ISqlConnections SqlConnections { get; set; }
public static void InitializeServices(IServiceProvider services)
{
SqlConnections = services.GetRequiredService<ISqlConnections>();
}
}
and in your Startup.cs Configure method
AppStatics.InitializeServices(app.ApplicationServices);
now you can access it like
using (var connection = AppStatics.SqlConnections.NewFor<LoginLogRow>())
Upvotes: 1