Browse Source

Fix SqlServer service injection bug

master
Savorboard 5 years ago
parent
commit
7343864654
3 changed files with 37 additions and 9 deletions
  1. +3
    -0
      src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs
  2. +33
    -0
      src/DotNetCore.CAP.SqlServer/Diagnostics/IProcessingServer.DiagnosticRegister.cs
  3. +1
    -9
      src/DotNetCore.CAP.SqlServer/IStorageInitializer.SqlServer.cs

+ 3
- 0
src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs View File

@@ -2,10 +2,12 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.


using System; using System;
using DotNetCore.CAP.Internal;
using DotNetCore.CAP.Persistence; using DotNetCore.CAP.Persistence;
using DotNetCore.CAP.SqlServer; using DotNetCore.CAP.SqlServer;
using DotNetCore.CAP.SqlServer.Diagnostics; using DotNetCore.CAP.SqlServer.Diagnostics;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;


// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
@@ -28,6 +30,7 @@ namespace DotNetCore.CAP
services.AddSingleton<IDataStorage, SqlServerDataStorage>(); services.AddSingleton<IDataStorage, SqlServerDataStorage>();
services.AddSingleton<IStorageInitializer, SqlServerStorageInitializer>(); services.AddSingleton<IStorageInitializer, SqlServerStorageInitializer>();
services.AddTransient<CapTransactionBase, SqlServerCapTransaction>(); services.AddTransient<CapTransactionBase, SqlServerCapTransaction>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IProcessingServer, DiagnosticRegister>());


services.Configure(_configure); services.Configure(_configure);
services.AddSingleton<IConfigureOptions<SqlServerOptions>, ConfigureSqlServerOptions>(); services.AddSingleton<IConfigureOptions<SqlServerOptions>, ConfigureSqlServerOptions>();


+ 33
- 0
src/DotNetCore.CAP.SqlServer/Diagnostics/IProcessingServer.DiagnosticRegister.cs View File

@@ -0,0 +1,33 @@
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Diagnostics;
using DotNetCore.CAP.Internal;

namespace DotNetCore.CAP.SqlServer.Diagnostics
{
public class DiagnosticRegister : IProcessingServer
{
private readonly DiagnosticProcessorObserver _diagnosticProcessorObserver;

public DiagnosticRegister(DiagnosticProcessorObserver diagnosticProcessorObserver)
{
_diagnosticProcessorObserver = diagnosticProcessorObserver;
}

public void Dispose()
{

}

public void Pulse()
{
}

public void Start()
{
DiagnosticListener.AllListeners.Subscribe(_diagnosticProcessorObserver);
}
}
}

+ 1
- 9
src/DotNetCore.CAP.SqlServer/IStorageInitializer.SqlServer.cs View File

@@ -1,12 +1,10 @@
// Copyright (c) .NET Core Community. All rights reserved. // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.


using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dapper; using Dapper;
using DotNetCore.CAP.Persistence; using DotNetCore.CAP.Persistence;
using DotNetCore.CAP.SqlServer.Diagnostics;
using Microsoft.Data.SqlClient; using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@@ -15,17 +13,14 @@ namespace DotNetCore.CAP.SqlServer
{ {
public class SqlServerStorageInitializer : IStorageInitializer public class SqlServerStorageInitializer : IStorageInitializer
{ {
private readonly DiagnosticProcessorObserver _diagnosticProcessorObserver;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOptions<SqlServerOptions> _options; private readonly IOptions<SqlServerOptions> _options;


public SqlServerStorageInitializer( public SqlServerStorageInitializer(
ILogger<SqlServerStorageInitializer> logger, ILogger<SqlServerStorageInitializer> logger,
IOptions<SqlServerOptions> options,
DiagnosticProcessorObserver diagnosticProcessorObserver)
IOptions<SqlServerOptions> options)
{ {
_options = options; _options = options;
_diagnosticProcessorObserver = diagnosticProcessorObserver;
_logger = logger; _logger = logger;
} }


@@ -50,11 +45,8 @@ namespace DotNetCore.CAP.SqlServer
} }


_logger.LogDebug("Ensuring all create database tables script are applied."); _logger.LogDebug("Ensuring all create database tables script are applied.");

DiagnosticListener.AllListeners.Subscribe(_diagnosticProcessorObserver);
} }



protected virtual string CreateDbTablesScript(string schema) protected virtual string CreateDbTablesScript(string schema)
{ {
var batchSql = var batchSql =


Loading…
Cancel
Save