Could not resolve type with token 01000034 from typeref (expected class 'Microsoft.JSInterop.DotNetObjectRef' in assembly 'Microsoft.JSInterop, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60')'
我使用Reshiru.Blazor.IndexedDb.Framework来使用我的浏览器的数据库。这是我如何实现它的:
我创建了一个类:
public class ApplicationDb : IndexedDb
{
public ApplicationDb(IJSRuntime jSRuntime, string name, int version) : base(jSRuntime, name, version) { }
public IndexedSet<Incident> Incidents { get; set; }
}
然后创建了一个存储库来使用这个:
public class IncidentRepository : IIncidentRepository
{
private IIndexedDbFactory IndexedDbFactory { get; set; }
private readonly Task<ApplicationDb> openingDbTask;
public IncidentRepository(IIndexedDbFactory indexedDbFactory, HttpClient httpClient)
{
IndexedDbFactory = indexedDbFactory;
HttpClient = httpClient;
openingDbTask = OpenDbAsync();
}
public async Task<Incident> AddIncident(Incident incident)
{
try
{
using (var db = await IndexedDbFactory.Create<ApplicationDb>())
{
db.Incidents.Add(incident);
await db.SaveChanges();
return incident;
}
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
throw;
}
}
}
然后添加到Program.cs
builder.Services.AddSingleton<IIndexedDbFactory, IndexedDbFactory>();
builder.Services.AddScoped<IIncidentRepository, IncidentRepository>();
1条答案
按热度按时间bihw5rsg1#
如果你还在问这个问题,你可以安装这个软件包“https://github.com/wtulloch/Blazor.IndexedDB”。如果你遇到一个未定义的“TimeGhost”,只需按ctrl+F5。