You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I did migrations and and update database using connected services
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:
I did migrations and and update database using connected services
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
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Describe the bug
I created a brand new Blazor App with Identity and Interactive Auto, using the Web App template.
I added the movie.cs file from Microsoft learning https://www.youtube.com/watch?v=ZN-CcfEY3Z8 and added scaffolding.
I did migrations and and update database using connected services
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
I created a brand new Blazor App with Identity and Interactive Auto, using the Web App template.
I added the movie.cs file from Microsoft learning https://www.youtube.com/watch?v=ZN-CcfEY3Z8 and added scaffolding.
I did migrations and and update database using connected services
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
The text was updated successfully, but these errors were encountered: