Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TheCyberCore opened this issue May 10, 2020 · 7 comments
Open
Labels
bug Something isn't working question Further information is requested

Comments

@TheCyberCore
Copy link

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?

@chanan chanan added bug Something isn't working Documentation labels May 10, 2020
@chanan
Copy link
Owner

chanan commented May 10, 2020

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 chanan added question Further information is requested and removed Documentation labels May 10, 2020
@TheCyberCore
Copy link
Author

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

BlazorStyledTest.zip

@chanan
Copy link
Owner

chanan commented May 11, 2020

Thanks! I will take a look tomorrow evening

@TheCyberCore
Copy link
Author

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'."

@chanan
Copy link
Owner

chanan commented May 11, 2020

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
Copy link
Owner

chanan commented May 13, 2020

@TheCyberCore were you able to get this working?

@TheCyberCore
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants