@@ -35,3 +35,7 @@ bin/ | |||||
/.idea | /.idea | ||||
Properties | Properties | ||||
/pack.bat | /pack.bat | ||||
/src/DotNetCore.CAP/project.json | |||||
/src/DotNetCore.CAP/packages.config | |||||
/src/DotNetCore.CAP/DotNetCore.CAP.Net47.csproj | |||||
/NuGet.config |
@@ -1,4 +1,5 @@ | |||||
using System.IO; | using System.IO; | ||||
using Microsoft.AspNetCore; | |||||
using Microsoft.AspNetCore.Builder; | using Microsoft.AspNetCore.Builder; | ||||
using Microsoft.AspNetCore.Hosting; | using Microsoft.AspNetCore.Hosting; | ||||
using Microsoft.Extensions.Configuration; | using Microsoft.Extensions.Configuration; | ||||
@@ -7,22 +8,30 @@ namespace Sample.RabbitMQ.SqlServer | |||||
{ | { | ||||
public class Program | public class Program | ||||
{ | { | ||||
//var config = new ConfigurationBuilder() | |||||
// .AddCommandLine(args) | |||||
// .AddEnvironmentVariables("ASPNETCORE_") | |||||
// .Build(); | |||||
//var host = new WebHostBuilder() | |||||
// .UseConfiguration(config) | |||||
// .UseKestrel() | |||||
// .UseContentRoot(Directory.GetCurrentDirectory()) | |||||
// .UseIISIntegration() | |||||
// .UseStartup<Startup>() | |||||
// .Build(); | |||||
//host.Run(); | |||||
public static void Main(string[] args) | public static void Main(string[] args) | ||||
{ | { | ||||
var config = new ConfigurationBuilder() | |||||
.AddCommandLine(args) | |||||
.AddEnvironmentVariables("ASPNETCORE_") | |||||
.Build(); | |||||
BuildWebHost(args).Run(); | |||||
} | |||||
var host = new WebHostBuilder() | |||||
.UseConfiguration(config) | |||||
.UseKestrel() | |||||
.UseContentRoot(Directory.GetCurrentDirectory()) | |||||
.UseIISIntegration() | |||||
public static IWebHost BuildWebHost(string[] args) => | |||||
WebHost.CreateDefaultBuilder(args) | |||||
.UseStartup<Startup>() | .UseStartup<Startup>() | ||||
.Build(); | .Build(); | ||||
host.Run(); | |||||
} | |||||
} | } | ||||
} | } |
@@ -23,7 +23,11 @@ namespace DotNetCore.CAP | |||||
services.AddScoped<ICapPublisher, CapPublisher>(); | services.AddScoped<ICapPublisher, CapPublisher>(); | ||||
services.AddTransient<ICallbackPublisher, CapPublisher>(); | services.AddTransient<ICallbackPublisher, CapPublisher>(); | ||||
services.AddTransient<IAdditionalProcessor, DefaultAdditionalProcessor>(); | services.AddTransient<IAdditionalProcessor, DefaultAdditionalProcessor>(); | ||||
AddSqlServerOptions(services); | |||||
} | |||||
private void AddSqlServerOptions(IServiceCollection services) | |||||
{ | |||||
var sqlServerOptions = new SqlServerOptions(); | var sqlServerOptions = new SqlServerOptions(); | ||||
_configure(sqlServerOptions); | _configure(sqlServerOptions); | ||||
@@ -32,9 +36,13 @@ namespace DotNetCore.CAP | |||||
{ | { | ||||
services.AddSingleton(x => | services.AddSingleton(x => | ||||
{ | { | ||||
var dbContext = (DbContext)x.GetService(sqlServerOptions.DbContextType); | |||||
sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | |||||
return sqlServerOptions; | |||||
using (var scope = x.CreateScope()) | |||||
{ | |||||
var provider = scope.ServiceProvider; | |||||
var dbContext = (DbContext)provider.GetService(sqlServerOptions.DbContextType); | |||||
sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | |||||
return sqlServerOptions; | |||||
} | |||||
}); | }); | ||||
} | } | ||||
else | else | ||||