2
私は、ASP.NETアプリケーションで使用するカスタムミドルウェアを作成しています。 私のミドルウェアは、AddServices
メソッドを使用してMicrosoft DIコンテナに挿入できるサービスによって異なります。DIが必要なカスタムミドルウェアをDNXでテストする方法は?
xUnitを使用してTestServer
を作成すると、Microsoft DIコンテナを呼び出してミドルウェアが依存するサービスを注入する場所がありません。
は私がTESTSERVERを作成し、その上で私のミドルウェアを追加する方法の詳細については、下記の例を参照してください:
/// <summary>
/// Create a server with the ASP.NET Core Logging Middleware registered without any configuration.
/// The server will throw an exception of type <typeparamref name="T"/> on every request.
/// </summary>
/// <typeparam name="T">The type of exception to throw.</typeparam>
/// <returns>A <see cref="TestServer"/> that can be used to unit test the middleware.</returns>
private TestServer CreateServerWithAspNetCoreLogging<T>()
where T : Exception, new()
{
return TestServer.Create(app =>
{
app.UseAspNetCoreLogging();
SetupTestServerToThrowOnEveryRequest<T>(app);
});
}
どこで、どのようにマイクロソフトDIコンテナの中に私のサービスを注入する必要がありますか?