【发布时间】:2020-11-09 10:44:46
【问题描述】:
提供对 Blazor 应用程序中本地存储的访问的库
将服务注入组件很容易:
@inject Blazored.LocalStorage.ILocalStorageService localStorage
如果我们想将其注入到后面的代码中:
[Inject]
private ILocalStorageService localStorage { get; set; }
但是假设我想将它注入到另一个服务中(比如说集中控制):
public class StorageManagement
{
public StorageManagement(LocalStorageService localStorage)
{
//How to initialize it here?
}
}
我不知道如何在StorageManagement的构造函数中初始化服务的实例,也不知道如何在Program.cs中设置StorageManagement的构造函数的参数:
builder.Services.AddSingleton(e => new StorageManagement(//?));
【问题讨论】:
标签: dependency-injection blazor blazor-client-side