Commit 68848027 authored by Savorboard's avatar Savorboard

Fix SqlServer options bug

parent 7021dc65
......@@ -17,7 +17,7 @@ namespace DotNetCore.CAP
public string Schema { get; set; } = DefaultSchema;
/// <summary>
/// EF dbcontext type.
/// EF DbContext
/// </summary>
internal Type DbContextType { get; set; }
......
......@@ -20,12 +20,13 @@ namespace DotNetCore.CAP.SqlServer
"Published", "Received"
};
private readonly TimeSpan _delay = TimeSpan.FromSeconds(1);
private readonly ILogger _logger;
private readonly SqlServerOptions _options;
private readonly TimeSpan _delay = TimeSpan.FromSeconds(1);
private readonly TimeSpan _waitingInterval = TimeSpan.FromMinutes(5);
public SqlServerCollectProcessor(ILogger<SqlServerCollectProcessor> logger,
public SqlServerCollectProcessor(
ILogger<SqlServerCollectProcessor> logger,
IOptions<SqlServerOptions> sqlServerOptions)
{
_logger = logger;
......
......@@ -10,6 +10,7 @@ using DotNetCore.CAP.Dashboard;
using DotNetCore.CAP.Dashboard.Monitoring;
using DotNetCore.CAP.Infrastructure;
using DotNetCore.CAP.Models;
using Microsoft.Extensions.Options;
namespace DotNetCore.CAP.SqlServer
{
......@@ -18,9 +19,9 @@ namespace DotNetCore.CAP.SqlServer
private readonly SqlServerOptions _options;
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));
}
......
......@@ -17,21 +17,22 @@ namespace DotNetCore.CAP.SqlServer
{
public class SqlServerStorage : IStorage
{
private readonly CapOptions _capOptions;
private readonly DiagnosticProcessorObserver _diagnosticProcessorObserver;
private readonly IDbConnection _existingConnection = null;
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<SqlServerOptions> options,
DiagnosticProcessorObserver diagnosticProcessorObserver)
{
_options = options.Value;
_options = options;
_diagnosticProcessorObserver = diagnosticProcessorObserver;
_logger = logger;
_capOptions = capOptions.Value;
_capOptions = capOptions;
}
public IStorageConnection GetConnection()
......@@ -51,9 +52,9 @@ namespace DotNetCore.CAP.SqlServer
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);
}
......@@ -128,7 +129,7 @@ END;";
internal IDbConnection CreateAndOpenConnection()
{
var connection = _existingConnection ?? new SqlConnection(_options.ConnectionString);
var connection = _existingConnection ?? new SqlConnection(_options.Value.ConnectionString);
if (connection.State == ConnectionState.Closed)
{
......
......@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Dapper;
using DotNetCore.CAP.Infrastructure;
using DotNetCore.CAP.Models;
using Microsoft.Extensions.Options;
namespace DotNetCore.CAP.SqlServer
{
......@@ -15,10 +16,12 @@ namespace DotNetCore.CAP.SqlServer
{
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; }
......
......@@ -13,7 +13,6 @@ namespace DotNetCore.CAP.SqlServer
public class SqlServerStorageTransaction : IStorageTransaction
{
private readonly IDbConnection _dbConnection;
private readonly string _schema;
public SqlServerStorageTransaction(SqlServerStorageConnection connection)
......
......@@ -14,7 +14,7 @@ namespace DotNetCore.CAP.SqlServer.Test
public SqlServerStorageConnectionTest()
{
_storage = new SqlServerStorageConnection(SqlSeverOptions.Value, CapOptions.Value);
_storage = new SqlServerStorageConnection(SqlSeverOptions, CapOptions);
}
[Fact]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment