BlazorStyled icon indicating copy to clipboard operation
BlazorStyled copied to clipboard

AddBlazorStyled() exception in ASP.NET Core blazor server project

Open TheCyberCore opened this issue 5 years ago • 7 comments

Hi, I ran in a little issue with the latest version of this library with .NET Core 3.1. The project was generated with the Visual Studio 2019 wizard. When adding the service via AddBlazorStyled() in Startup.ConfigureServices() the following exception occurs.

System.InvalidOperationException: "Cannot resolve 'BlazorStyled.IStyled' from root provider because it requires scoped service 'BlazorStyled.Stylesheets.IStyleSheet'."

As IStyleSheet and its implementations are internal elements of BlazorStyled, I am also not able to add the DI object manually.

I think this is a bug?

TheCyberCore avatar May 10 '20 18:05 TheCyberCore

I haven’t seen this issue. I do test both on client and server side projects.

The current master branch of the project doesn’t have that class anymore - as well as the preview release in Nuget. Could you zip up the project and attach it or post it on github and I can take a look?

chanan avatar May 10 '20 19:05 chanan

I created a minimum test project. The error occurs when trying to get access to IStyled in Startup.Configure().

BlazorStyledTest.zip

TheCyberCore avatar May 11 '20 03:05 TheCyberCore

Thanks! I will take a look tomorrow evening

chanan avatar May 11 '20 03:05 chanan

Thank you :) I now also tested the latest preview 3.00 alpha 5 and the error still persists but changed slightly.

System.InvalidOperationException: "Cannot resolve 'BlazorStyled.IStyled' from root provider because it requires scoped service 'BlazorStyled.Internal.ScriptManager'."

TheCyberCore avatar May 11 '20 03:05 TheCyberCore

Took a quick look. Remove the line in Startup.cs -> Configure method: IStyled styled = app.ApplicationServices.GetRequiredService<IStyled>();. Once you do that, you can use it in Inde.razor (or where ever) either by using the <Styled /> tag or if you want to use the API you can use: @inject BlazorStyled.IStyled Styled

chanan avatar May 11 '20 03:05 chanan

@TheCyberCore were you able to get this working?

chanan avatar May 13 '20 20:05 chanan

@chanan Yes, thank you. This works. But it does not really fit in my app, because the theming variables should be active before the first razor subpage loads. I also tried to initialize the theming within the razor root page/layout page, but the injection seems to work only on sub-page level.

TheCyberCore avatar May 14 '20 01:05 TheCyberCore