Parcourir la source

Fix SqlServer service injection bug

master
Savorboard il y a 5 ans
Parent
révision
7343864654
3 fichiers modifiés avec 37 ajouts et 9 suppressions
  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 Voir le fichier

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

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

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

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


+ 33
- 0
src/DotNetCore.CAP.SqlServer/Diagnostics/IProcessingServer.DiagnosticRegister.cs Voir le fichier

@@ -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 Voir le fichier

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

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

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

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

DiagnosticListener.AllListeners.Subscribe(_diagnosticProcessorObserver);
}


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


Chargement…
Annuler
Enregistrer