ASP.Net Core2.0でReactを使おうと勉強してたら軽くハマってしまったが、エラーメッセージでググったら瞬殺でした・・・
Setting Up ReactJS on .NET Core 2.0, InvalidOperationException
以下、軽く日本語訳 + 説明
and trying to add ReactJS by following the tutorial here: (https://reactjs.net/getting-started/tutorial.html)
When going through the tutorial, however, I get an "InvalidOperationException" error that says: 'Cannot resolve scoped service 'React.AspNet.HttpContextLifetimeProvider+PerRequestRegistrations' from root provider.'
Specifically the error comes from the app.UseReact(config=> ... ) section of the tutorial.
チュートリアルに従ってコーディングしてたら『app.UseReact(config=> ... )』の箇所でInvalidOperationExceptionになっちゃった ><
see https://github.com/reactjs/React.NET/issues/433
change in Startup.cs
public void ConfigureServices(IServiceCollection services)
to
public IServiceProvider ConfigureServices(IServiceCollection services)
and return services.BuildServiceProvider();
これをみてごらん
Error on startup in core 2.0 'React.AspNet.HttpContextLifetimeProvider` #433
Startup.csのConfigureServicesの返り値をIServiceProvider にして
services.BuildServiceProvider()を返すんだ。
Before
public void ConfigureServices(IServiceCollection services)
{
}
After
public IServiceProvider ConfigureServices(IServiceCollection services)
{
return services.BuildServiceProvider();
}