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

Blazor Scaffolding is broken due to regression #59491

Open
1 task done
coderdnewbie opened this issue Dec 15, 2024 · 0 comments
Open
1 task done

Blazor Scaffolding is broken due to regression #59491

coderdnewbie opened this issue Dec 15, 2024 · 0 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@coderdnewbie
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

  1. I created a brand new Blazor App with Identity and Interactive Auto, using the Web App template.

  2. I added the movie.cs file from Microsoft learning https://www.youtube.com/watch?v=ZN-CcfEY3Z8 and added scaffolding.

  3. I did migrations and and update database using connected services

  4. Fixed some scaffolding errors. Tried to go to localhost movies page. Got the following Exception:

InvalidOperationException: Cannot provide a value for property 'DbFactory' on type 'BlazorAppId.Components.Pages.MoviePages.Index'. There is no registered service of type 'Microsoft.EntityFrameworkCore.IDbContextFactory`1[BlazorAppId.Data.ApplicationDbContext]'.

The fix in program.cs, is to change builder.Services.AddDbContext<...>to builder.Services.AddDbContextFactory<...>and then it works as expected.

The issue is that the scaffolding pages are injecting:

@Inject IDbContextFactory<BlazorAppId.Data.ApplicationDbContext> DbFactory

but the program.cs is set as builder.Services.AddDbContext<...>

This is a regression as this used to work in .Net 8.0.

@Danoth, Please can you test https://www.youtube.com/watch?v=ZN-CcfEY3Z8 scaffolding again? I suspect it will not work with dotnet 9.0 and be a source of frustration to people trying to learn Blazor.

Expected Behavior

The regression is fixed so scaffolding works like .Net 8.0 where builder.Services.AddDbContextFactory<...> was used.

Steps To Reproduce

  1. I created a brand new Blazor App with Identity and Interactive Auto, using the Web App template.

  2. I added the movie.cs file from Microsoft learning https://www.youtube.com/watch?v=ZN-CcfEY3Z8 and added scaffolding.

  3. I did migrations and and update database using connected services

  4. Fixed some scaffolding errors. Tried to go to localhost movies page. Got the following Exception:

InvalidOperationException: Cannot provide a value for property 'DbFactory' on type 'BlazorAppId.Components.Pages.MoviePages.Index'. There is no registered service of type 'Microsoft.EntityFrameworkCore.IDbContextFactory`1[BlazorAppId.Data.ApplicationDbContext]'.

The fix in program.cs, is to change builder.Services.AddDbContext<...>to builder.Services.AddDbContextFactory<...>and then it works as expected.

Exceptions (if any)

InvalidOperationException: Cannot provide a value for property 'DbFactory' on type 'BlazorAppId.Components.Pages.MoviePages.Index'. There is no registered service of type 'Microsoft.EntityFrameworkCore.IDbContextFactory`1[BlazorAppId.Data.ApplicationDbContext]'.

.NET Version

.Net 9.0

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

1 participant