File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -150,9 +150,13 @@ protected static async Task<string> RenderRazorPageAsync(Compilation compilation
150150 }
151151 } ) ;
152152 var app = appBuilder . Build ( ) ;
153+
154+ // Create a service scope to properly handle scoped services like IViewBufferScope.
155+ // ASP.NET Core's DI validation prevents resolving scoped services from the root provider.
156+ using var scope = app . Services . CreateScope ( ) ;
153157 var httpContext = new DefaultHttpContext
154158 {
155- RequestServices = app . Services
159+ RequestServices = scope . ServiceProvider
156160 } ;
157161 var requestFeature = new HttpRequestFeature
158162 {
@@ -184,7 +188,7 @@ protected static async Task<string> RenderRazorPageAsync(Compilation compilation
184188 . ToImmutableArray ( ) ;
185189
186190 // Render the page.
187- var view = ActivatorUtilities . CreateInstance < RazorView > ( app . Services ,
191+ var view = ActivatorUtilities . CreateInstance < RazorView > ( scope . ServiceProvider ,
188192 /* IReadOnlyList<IRazorPage> viewStartPages */ viewStarts ,
189193 /* IRazorPage razorPage */ page ) ;
190194 await view . RenderAsync ( viewContext ) ;
You can’t perform that action at this time.
0 commit comments