public static void Register(IServiceCollection services, IConfiguration configuration) { // Middleware must be injected as a singleton. var problemDetailsConfiguration = new ProblemDetailsConfiguration(); configuration.Bind(nameof(ProblemDetailsConfiguration), problemDetailsConfiguration); services.AddSingleton(problemDetailsConfiguration); // This is a dependency within the Middleware class, so it too must be injected as a singleton. services.AddSingleton(typeof(IProblemDetailsFactory), typeof(ProblemDetailsFactory)); }
private static ProblemDetailsWithNotifications CreateExpectedProblemDetailsWithNotifications(ProblemDetailsConfiguration configuration) { var expected = new ProblemDetailsWithNotifications { Type = "https://tools.ietf.org/html/rfc7231#section-6.5.1", Title = "Bad Request", Status = (int)HttpStatusCode.BadRequest, Detail = "Review the notifications for details.", Instance = $"urn:{configuration.UrnName}:error:{ProblemDetailsFactory.BadRequestId}", Notifications = new List <Notification>() }; expected.Extensions["traceId"] = Tracking.TraceId; return(expected); }