[Fixes #4218] Adds a comment justifying the use of service locator in this case

This commit is contained in:
jacalvar 2016-05-25 12:57:35 -07:00
parent 4b5df98bc3
commit ed8c744041
1 changed files with 4 additions and 0 deletions

View File

@ -97,6 +97,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor
throw new ArgumentNullException(nameof(context));
}
// This GetRequiredService call is by design. ViewBufferScope is a scoped service, RazorViewEngine
// is the component responsible for creating RazorViews and it is a Singleton service. It doesn't
// have access to the RequestServices so requiring the service when we render the page is the best
// we can do.
_bufferScope = context.HttpContext.RequestServices.GetRequiredService<IViewBufferScope>();
var bodyWriter = await RenderPageAsync(RazorPage, context, invokeViewStarts: true);
await RenderLayoutAsync(context, bodyWriter);