@@ -17,7 +17,7 @@ namespace DotNetCore.CAP | |||||
public string Schema { get; set; } = DefaultSchema; | public string Schema { get; set; } = DefaultSchema; | ||||
/// <summary> | /// <summary> | ||||
/// EF dbcontext type. | |||||
/// EF DbContext | |||||
/// </summary> | /// </summary> | ||||
internal Type DbContextType { get; set; } | internal Type DbContextType { get; set; } | ||||
@@ -20,12 +20,13 @@ namespace DotNetCore.CAP.SqlServer | |||||
"Published", "Received" | "Published", "Received" | ||||
}; | }; | ||||
private readonly TimeSpan _delay = TimeSpan.FromSeconds(1); | |||||
private readonly ILogger _logger; | private readonly ILogger _logger; | ||||
private readonly SqlServerOptions _options; | private readonly SqlServerOptions _options; | ||||
private readonly TimeSpan _delay = TimeSpan.FromSeconds(1); | |||||
private readonly TimeSpan _waitingInterval = TimeSpan.FromMinutes(5); | private readonly TimeSpan _waitingInterval = TimeSpan.FromMinutes(5); | ||||
public SqlServerCollectProcessor(ILogger<SqlServerCollectProcessor> logger, | |||||
public SqlServerCollectProcessor( | |||||
ILogger<SqlServerCollectProcessor> logger, | |||||
IOptions<SqlServerOptions> sqlServerOptions) | IOptions<SqlServerOptions> sqlServerOptions) | ||||
{ | { | ||||
_logger = logger; | _logger = logger; | ||||
@@ -10,6 +10,7 @@ using DotNetCore.CAP.Dashboard; | |||||
using DotNetCore.CAP.Dashboard.Monitoring; | using DotNetCore.CAP.Dashboard.Monitoring; | ||||
using DotNetCore.CAP.Infrastructure; | using DotNetCore.CAP.Infrastructure; | ||||
using DotNetCore.CAP.Models; | using DotNetCore.CAP.Models; | ||||
using Microsoft.Extensions.Options; | |||||
namespace DotNetCore.CAP.SqlServer | namespace DotNetCore.CAP.SqlServer | ||||
{ | { | ||||
@@ -18,9 +19,9 @@ namespace DotNetCore.CAP.SqlServer | |||||
private readonly SqlServerOptions _options; | private readonly SqlServerOptions _options; | ||||
private readonly SqlServerStorage _storage; | private readonly SqlServerStorage _storage; | ||||
public SqlServerMonitoringApi(IStorage storage, SqlServerOptions options) | |||||
public SqlServerMonitoringApi(IStorage storage, IOptions<SqlServerOptions> options) | |||||
{ | { | ||||
_options = options ?? throw new ArgumentNullException(nameof(options)); | |||||
_options = options.Value ?? throw new ArgumentNullException(nameof(options)); | |||||
_storage = storage as SqlServerStorage ?? throw new ArgumentNullException(nameof(storage)); | _storage = storage as SqlServerStorage ?? throw new ArgumentNullException(nameof(storage)); | ||||
} | } | ||||
@@ -17,21 +17,22 @@ namespace DotNetCore.CAP.SqlServer | |||||
{ | { | ||||
public class SqlServerStorage : IStorage | public class SqlServerStorage : IStorage | ||||
{ | { | ||||
private readonly CapOptions _capOptions; | |||||
private readonly DiagnosticProcessorObserver _diagnosticProcessorObserver; | |||||
private readonly IDbConnection _existingConnection = null; | |||||
private readonly ILogger _logger; | private readonly ILogger _logger; | ||||
private readonly SqlServerOptions _options; | |||||
private readonly IOptions<CapOptions> _capOptions; | |||||
private readonly IOptions<SqlServerOptions> _options; | |||||
private readonly IDbConnection _existingConnection = null; | |||||
private readonly DiagnosticProcessorObserver _diagnosticProcessorObserver; | |||||
public SqlServerStorage(ILogger<SqlServerStorage> logger, | |||||
public SqlServerStorage( | |||||
ILogger<SqlServerStorage> logger, | |||||
IOptions<CapOptions> capOptions, | IOptions<CapOptions> capOptions, | ||||
IOptions<SqlServerOptions> options, | IOptions<SqlServerOptions> options, | ||||
DiagnosticProcessorObserver diagnosticProcessorObserver) | DiagnosticProcessorObserver diagnosticProcessorObserver) | ||||
{ | { | ||||
_options = options.Value; | |||||
_options = options; | |||||
_diagnosticProcessorObserver = diagnosticProcessorObserver; | _diagnosticProcessorObserver = diagnosticProcessorObserver; | ||||
_logger = logger; | _logger = logger; | ||||
_capOptions = capOptions.Value; | |||||
_capOptions = capOptions; | |||||
} | } | ||||
public IStorageConnection GetConnection() | public IStorageConnection GetConnection() | ||||
@@ -51,9 +52,9 @@ namespace DotNetCore.CAP.SqlServer | |||||
return; | return; | ||||
} | } | ||||
var sql = CreateDbTablesScript(_options.Schema); | |||||
var sql = CreateDbTablesScript(_options.Value.Schema); | |||||
using (var connection = new SqlConnection(_options.ConnectionString)) | |||||
using (var connection = new SqlConnection(_options.Value.ConnectionString)) | |||||
{ | { | ||||
await connection.ExecuteAsync(sql); | await connection.ExecuteAsync(sql); | ||||
} | } | ||||
@@ -128,7 +129,7 @@ END;"; | |||||
internal IDbConnection CreateAndOpenConnection() | internal IDbConnection CreateAndOpenConnection() | ||||
{ | { | ||||
var connection = _existingConnection ?? new SqlConnection(_options.ConnectionString); | |||||
var connection = _existingConnection ?? new SqlConnection(_options.Value.ConnectionString); | |||||
if (connection.State == ConnectionState.Closed) | if (connection.State == ConnectionState.Closed) | ||||
{ | { | ||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks; | |||||
using Dapper; | using Dapper; | ||||
using DotNetCore.CAP.Infrastructure; | using DotNetCore.CAP.Infrastructure; | ||||
using DotNetCore.CAP.Models; | using DotNetCore.CAP.Models; | ||||
using Microsoft.Extensions.Options; | |||||
namespace DotNetCore.CAP.SqlServer | namespace DotNetCore.CAP.SqlServer | ||||
{ | { | ||||
@@ -15,10 +16,12 @@ namespace DotNetCore.CAP.SqlServer | |||||
{ | { | ||||
private readonly CapOptions _capOptions; | private readonly CapOptions _capOptions; | ||||
public SqlServerStorageConnection(SqlServerOptions options, CapOptions capOptions) | |||||
public SqlServerStorageConnection( | |||||
IOptions<SqlServerOptions> options, | |||||
IOptions<CapOptions> capOptions) | |||||
{ | { | ||||
_capOptions = capOptions; | |||||
Options = options; | |||||
_capOptions = capOptions.Value; | |||||
Options = options.Value; | |||||
} | } | ||||
public SqlServerOptions Options { get; } | public SqlServerOptions Options { get; } | ||||
@@ -13,7 +13,6 @@ namespace DotNetCore.CAP.SqlServer | |||||
public class SqlServerStorageTransaction : IStorageTransaction | public class SqlServerStorageTransaction : IStorageTransaction | ||||
{ | { | ||||
private readonly IDbConnection _dbConnection; | private readonly IDbConnection _dbConnection; | ||||
private readonly string _schema; | private readonly string _schema; | ||||
public SqlServerStorageTransaction(SqlServerStorageConnection connection) | public SqlServerStorageTransaction(SqlServerStorageConnection connection) | ||||
@@ -14,7 +14,7 @@ namespace DotNetCore.CAP.SqlServer.Test | |||||
public SqlServerStorageConnectionTest() | public SqlServerStorageConnectionTest() | ||||
{ | { | ||||
_storage = new SqlServerStorageConnection(SqlSeverOptions.Value, CapOptions.Value); | |||||
_storage = new SqlServerStorageConnection(SqlSeverOptions, CapOptions); | |||||
} | } | ||||
[Fact] | [Fact] | ||||