【发布时间】:2024-01-08 06:41:01
【问题描述】:
我正在尝试遵循this 教程,但收到此错误
参数 6:不能从 'TableDependency.SqlClient.Base.Enums.DmlTriggerType' 到 'TableDependency.SqlClient.Base.Abstracts.ITableDependencyFilter' (CS1503)
另外,在同一个教程中,作者在启动文件中使用了 Hubcontext
services.AddScoped<IHubContext<NonProductionHub>, HubContext<NonProductionHub>>();
我不确定它是否正确,因为我在 HubContext 而不是 IHubContext 上收到以下错误
找不到类型或命名空间名称“HubContext”(您是 缺少 using 指令或程序集引用?)
public class InventoryDatabaseSubscription : IDatabaseSubscription
{
private bool disposedValue = false;
private readonly IInventoryRepository _repository;
private readonly IHubContext<NonProductionHub> _hubContext;
private SqlTableDependency<Apps> _tableDependency;
public InventoryDatabaseSubscription(IInventoryRepository repository, IHubContext<NonProductionHub> hubContext)
{
_repository = repository;
_hubContext = hubContext;
}
public void Configure(string DefaultConnection)
{
_tableDependency = new SqlTableDependency<Apps>(DefaultConnection, null, null, null, null, DmlTriggerType.All);
_tableDependency.OnChanged += Changed;
_tableDependency.OnError += TableDependency_OnError;
_tableDependency.Start();
Console.WriteLine("Waiting for receiving notifications...");
}
private void TableDependency_OnError(object sender, ErrorEventArgs e)
{
Console.WriteLine($"SqlTableDependency error: {e.Error.Message}");
}
private void Changed(object sender, RecordChangedEventArgs<Apps> e)
{
if (e.ChangeType != ChangeType.None)
{
// TODO: manage the changed entity
var changedEntity = e.Entity;
_hubContext.Clients.All.SendAsync("UpdateCatalog", _repository.Apps);
}
}
#region IDisposable
~InventoryDatabaseSubscription()
{
Dispose(false);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_tableDependency.Stop();
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
【问题讨论】:
标签: asp.net-core .net-core signalr asp.net-core-2.2 sqldependency