c# - 在类库中使用 AddServerSideBlazor()
问题描述
我正在尝试像这样设置我自己的服务集合:
public static void AddMyServices(this IServiceCollection services)
{
services.AddServerSideBlazor();
//services.AddTransient<IMyService, MyService>();
}
我不知道如何让它运行,我尝试添加几个 NuGet 引用,但没有一个起作用。例如Microsoft.AspNetCore.Components.Web
开始AddServerSideBlazor();
工作。
我想在我的 Startup.cs 中这样使用它:
public void ConfigureServices(IServiceCollection services)
{
services.AddMyServices();
}
我得到的错误:
“IServiceCollection”不包含“AddServerSideBlazor”的定义,并且找不到接受“IServiceCollection”类型的第一个参数的可访问扩展方法“AddServerSideBlazor”(您是否缺少 using 指令或程序集引用?)
编辑:经过更多研究后,我认为正确的包是
Microsoft.AspNetCore.App.Ref
但通过 NuGet 添加它会给我这个错误:
Microsoft.AspNetCore.App.Ref 5.0.0 包的包类型 DotnetPlatform 与此项目不兼容。
解决方案
您将需要扩展 IServiceCollection。
public static Microsoft.Extensions.DependencyInjection.IServerSideBlazorBuilder AddServerSideBlazor (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.AspNetCore.Components.Server.CircuitOptions>? configure = default);
推荐阅读
- ruby-on-rails - 如何在 ruby on rails 中设置书签链接
- javascript - 将json数据从JS每个循环传递到JS函数时输入错误意外结束
- r - 根据字符串值提取数据
- android - 改造请求正文在 @Body 参数中添加双引号
- javascript - 光线投射墙没有画得一样宽
- javascript - 在 mongo db 中将日期格式更改为另一种格式
- javascript - (节点:71307)[DEP0079] 弃用警告
- postgresql - Postgres 中的长度和精度问题
- asp.net-mvc - ASP.NET MVC 5: UserManager.CreateAsync(user, model.Password); 没有将用户添加到数据库
- php - 无法更改上传文件的文件夹位置