使用 Ant Design of Blazor遇到的一个问题

在创建Ant Design of Blazor的时候,遇到一个问题,在app.razor添加

<AntContainer />  

之后,运行的的时候报错。 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Cannot provide a value for property 'NotificationService' on type 'AntDesign.Notification'. There is no registered service of type 'AntDesign.NotificationService'. System.InvalidOperationException: Cannot provide a value for property 'NotificationService' on type 'AntDesign.Notification'. There is no registered service of type 'AntDesign.NotificationService'.

因为我创建的项目是

所以应该把Service.AddAntDesign();写在program.cs里面,而不是写在startup.cs里面

 因为hosted的模板项目,是blazor wasm的。blazor是server side,就注册到hostbuilder上的service,如果是wasm,就注册在webassemblybuilder上。感谢James的解答。

猜你喜欢

转载自blog.csdn.net/qq_38436796/article/details/106938733