Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit d466cdb

Browse files
khellangSteveSandersonMS
authored andcommitted
Use built-in GetRequiredService<T>
1 parent 5bdb771 commit d466cdb

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/Microsoft.AspNetCore.SpaServices/Prerendering/SpaPrerenderingExtensions.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNetCore.NodeServices;
88
using Microsoft.AspNetCore.SpaServices;
99
using Microsoft.AspNetCore.SpaServices.Prerendering;
10+
using Microsoft.Extensions.DependencyInjection;
1011
using System;
1112
using System.Threading.Tasks;
1213

@@ -41,9 +42,9 @@ public static void UsePrerendering(
4142
var appBuilder = spaBuilder.AppBuilder;
4243
var serviceProvider = appBuilder.ApplicationServices;
4344
var nodeServices = GetNodeServices(serviceProvider);
44-
var applicationStoppingToken = GetRequiredService<IApplicationLifetime>(serviceProvider)
45+
var applicationStoppingToken = serviceProvider.GetRequiredService<IApplicationLifetime>()
4546
.ApplicationStopping;
46-
var applicationBasePath = GetRequiredService<IHostingEnvironment>(serviceProvider)
47+
var applicationBasePath = serviceProvider.GetRequiredService<IHostingEnvironment>()
4748
.ContentRootPath;
4849
var moduleExport = new JavaScriptModuleExport(entryPoint);
4950

@@ -92,12 +93,6 @@ public static void UsePrerendering(
9293
});
9394
}
9495

95-
private static T GetRequiredService<T>(IServiceProvider serviceProvider) where T: class
96-
{
97-
return (T)serviceProvider.GetService(typeof(T))
98-
?? throw new Exception($"Could not resolve service of type {typeof(T).FullName} in service provider.");
99-
}
100-
10196
private static async Task ApplyRenderResult(HttpContext context, RenderToStringResult renderResult)
10297
{
10398
if (!string.IsNullOrEmpty(renderResult.RedirectUrl))

0 commit comments

Comments
 (0)