Explorar el Código

resolve database connectionstring into SqlServerOptions.

master
yangxiaodong hace 7 años
padre
commit
9acccdaefb
Se han modificado 1 ficheros con 15 adiciones y 2 borrados
  1. +15
    -2
      src/DotNetCore.CAP.EntityFrameworkCore/CAP.SqlServerCapOptionsExtension.cs

+ 15
- 2
src/DotNetCore.CAP.EntityFrameworkCore/CAP.SqlServerCapOptionsExtension.cs Ver fichero

@@ -1,6 +1,7 @@
using System; using System;
using DotNetCore.CAP.EntityFrameworkCore; using DotNetCore.CAP.EntityFrameworkCore;
using DotNetCore.CAP.Processor; using DotNetCore.CAP.Processor;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;


// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
@@ -22,11 +23,23 @@ namespace DotNetCore.CAP
services.AddScoped<ICapPublisher, CapPublisher>(); services.AddScoped<ICapPublisher, CapPublisher>();
services.AddTransient<IAdditionalProcessor, DefaultAdditionalProcessor>(); services.AddTransient<IAdditionalProcessor, DefaultAdditionalProcessor>();


services.Configure(_configure);

var sqlServerOptions = new SqlServerOptions(); var sqlServerOptions = new SqlServerOptions();
_configure(sqlServerOptions); _configure(sqlServerOptions);

var provider = TempBuildService(services);
var dbContextObj = provider.GetService(sqlServerOptions.DbContextType);
if (dbContextObj != null)
{
var dbContext = (DbContext)dbContextObj;
sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString;
}
services.Configure(_configure);
services.AddSingleton(sqlServerOptions); services.AddSingleton(sqlServerOptions);
} }

private IServiceProvider TempBuildService(IServiceCollection services)
{
return services.BuildServiceProvider();
}
} }
} }

Cargando…
Cancelar
Guardar