Переглянути джерело

升级Pomelo.EntityFrameworkCore.MySql

td_orm
H Vs 1 рік тому
джерело
коміт
f3c840e995
5 змінених файлів з 72 додано та 10 видалено
  1. +4
    -2
      HealthMonitor.Core/Dal/Factory/GpsCardAccessorFactory.cs
  2. +12
    -5
      HealthMonitor.Core/Dal/Factory/HealthMonitorAccessorFactory.cs
  3. +48
    -0
      HealthMonitor.Core/Dal/Factory/HealthMonitorTDengineAccessorFactory.cs
  4. +1
    -1
      HealthMonitor.Core/HealthMonitor.Core.csproj
  5. +7
    -2
      HealthMonitor.WebApi/Program.cs

+ 4
- 2
HealthMonitor.Core/Dal/Factory/GpsCardAccessorFactory.cs Переглянути файл

@@ -25,8 +25,10 @@ namespace HealthMonitor.Core.Dal.Factory

public virtual IGpsCardDataAccessor GetDbContext()
{
var options = new DbContextOptionsBuilder<GpsCardContext>()
.UseMySql(_configuration.GetConnectionString("GpsCard_Connection_String"))
var mySqlCon = _configuration.GetConnectionString("GpsCard_Connection_String");
var serverVersion = ServerVersion.AutoDetect(mySqlCon);
var options = new DbContextOptionsBuilder<GpsCardContext>()
.UseMySql(mySqlCon,serverVersion)
.UseLoggerFactory(_loggerFactory)
.Options;



+ 12
- 5
HealthMonitor.Core/Dal/Factory/HealthMonitorAccessorFactory.cs Переглянути файл

@@ -25,12 +25,19 @@ namespace HealthMonitor.Core.Dal.Factory

public virtual IHealthMonitorDataAccessor GetDbContext()
{
var options = new DbContextOptionsBuilder<HealthMonitorContext>()
.UseMySql(_configuration.GetConnectionString("HealthMonitor_Connection_String"))
.UseLoggerFactory(_loggerFactory)
.Options;
//var options = new DbContextOptionsBuilder<HealthMonitorContext>()
// .UseMySql(_configuration.GetConnectionString("HealthMonitor_Connection_String"))
// .UseLoggerFactory(_loggerFactory)
// .Options;

var context = new HealthMonitorContext(options);
var mySqlCon = _configuration.GetConnectionString("HealthMonitor_Connection_String");
var serverVersion = ServerVersion.AutoDetect(mySqlCon);
var options = new DbContextOptionsBuilder<HealthMonitorContext>()
.UseMySql(mySqlCon, serverVersion)
.UseLoggerFactory(_loggerFactory)
.Options;

var context = new HealthMonitorContext(options);
return new EfCoreDataAccessor(context);

////AOP需要依赖DI


+ 48
- 0
HealthMonitor.Core/Dal/Factory/HealthMonitorTDengineAccessorFactory.cs Переглянути файл

@@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using HealthMonitor.Core.Context;
using HealthMonitor.Core.DbLog;
using HealthMonitor.Core.Dal.EfCoreImpl;

namespace HealthMonitor.Core.Dal.Factory
{
/// <summary>
/// 瞬态HealthMonitorContext构建帮助类
/// </summary>
public class HealthMonitorTDengineAccessorFactory
{
private readonly IConfiguration _configuration;
private readonly ILogger<HealthMonitorTDengineAccessorFactory> _logger;
private readonly ILoggerFactory _loggerFactory;

public HealthMonitorTDengineAccessorFactory(IConfiguration configuration, ILogger<HealthMonitorTDengineAccessorFactory> logger, IEfCoreLoggerProvider loggerProvider)
{
_configuration = configuration;
_logger = logger;
_loggerFactory = new LoggerFactory(new[] { loggerProvider });
}

//public virtual IHealthMonitorDataAccessor GetDbContext()
//{
// //var options = new DbContextOptionsBuilder<HealthMonitorContext>()
// // .UseMySql(_configuration.GetConnectionString("HealthMonitor_Connection_String"))
// // .UseLoggerFactory(_loggerFactory)
// // .Options;

// //var context = new HealthMonitorContext(options);
// //return new EfCoreDataAccessor(context);

// ////AOP需要依赖DI
// //var services = new ServiceCollection();
// //services.AddTransient<IGpsCardDataAccessor, EfCoreDataAccessor>(sp =>
// //{
// // var context = new GpsCardContext(options);
// // return new EfCoreDataAccessor(context);
// //});

// //var provider = services.BuildDynamicProxyProvider();
// //return provider.GetRequiredService<IGpsCardDataAccessor>();
//}
}
}

+ 1
- 1
HealthMonitor.Core/HealthMonitor.Core.csproj Переглянути файл

@@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="AspectCore.Extensions.DependencyInjection" Version="2.3.0" />
<PackageReference Include="CSRedisCore" Version="3.6.8" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.7" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
</ItemGroup>

<ItemGroup>


+ 7
- 2
HealthMonitor.WebApi/Program.cs Переглянути файл

@@ -58,13 +58,18 @@ namespace HealthMonitor.WebApi
.AddDbContextPool<GpsCardContext>((sp, options) =>
{
var loggerFactory = sp.GetRequiredService<EfCoreLoggerFactory>();
options.UseMySql(builder.Configuration.GetConnectionString("GpsCard_Connection_String"))
var mySqlCon = builder.Configuration.GetConnectionString("GpsCard_Connection_String");
var serverVersion = ServerVersion.AutoDetect(mySqlCon);
options.UseMySql(mySqlCon, serverVersion)
.UseLoggerFactory(loggerFactory);
}, poolSize: 64) // health_monitor
.AddDbContextPool<HealthMonitorContext>((sp, options) =>
{
var loggerFactory = sp.GetRequiredService<EfCoreLoggerFactory>();
options.UseMySql(builder.Configuration.GetConnectionString("HealthMonitor_Connection_String"))
var mySqlCon = builder.Configuration.GetConnectionString("HealthMonitor_Connection_String");
var serverVersion = ServerVersion.AutoDetect(mySqlCon);
options.UseMySql(mySqlCon, serverVersion)
.UseLoggerFactory(loggerFactory);
}, poolSize: 64); ;



Завантаження…
Відмінити
Зберегти