在创建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的解答。