コード例 #1
0
ファイル: DependencyRegistrar.cs プロジェクト: penblade/Tips
        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));
        }
コード例 #2
0
        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);
        }