Nice
3 years ago
5 changed files with 53 additions and 51 deletions
@ -0,0 +1,38 @@ |
|||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Gear.Infrastructure.Extensions |
||||
|
{ |
||||
|
public static class FreeSqlManager |
||||
|
{ |
||||
|
private static readonly IdleBus<IFreeSql> ib = new(TimeSpan.FromMinutes(10)); |
||||
|
|
||||
|
public static void RegisterFreeSql(this IConfiguration configuration, string configurationKey = "ConnectionString") |
||||
|
{ |
||||
|
string connectionString = configuration[configurationKey]; |
||||
|
ib.TryRegister(configurationKey, () => |
||||
|
{ |
||||
|
string fsdy = (configuration["FreeSql.DataType"] ?? "SqlServer").ToUpper(); |
||||
|
|
||||
|
FreeSql.FreeSqlBuilder builder = new(); |
||||
|
if (fsdy == "SqlServer".ToUpper()) |
||||
|
builder.UseConnectionString(FreeSql.DataType.SqlServer, connectionString); |
||||
|
if (fsdy == "MySql".ToUpper()) |
||||
|
builder.UseConnectionString(FreeSql.DataType.MySql, connectionString); |
||||
|
if (fsdy == "Oracle".ToUpper()) |
||||
|
builder.UseConnectionString(FreeSql.DataType.Oracle, connectionString); |
||||
|
|
||||
|
return builder.Build(); |
||||
|
}); |
||||
|
} |
||||
|
public static IFreeSql GetFreeSql(string configurationKey = "ConnectionString") |
||||
|
{ |
||||
|
return ib.Get(configurationKey); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue