diff --git a/src/Middleware/Diagnostics/ref/Microsoft.AspNetCore.Diagnostics.netcoreapp.cs b/src/Middleware/Diagnostics/ref/Microsoft.AspNetCore.Diagnostics.netcoreapp.cs index 6d400fb3f4..10b5258f37 100644 --- a/src/Middleware/Diagnostics/ref/Microsoft.AspNetCore.Diagnostics.netcoreapp.cs +++ b/src/Middleware/Diagnostics/ref/Microsoft.AspNetCore.Diagnostics.netcoreapp.cs @@ -105,3 +105,11 @@ namespace Microsoft.AspNetCore.Diagnostics public System.Threading.Tasks.Task Invoke(Microsoft.AspNetCore.Http.HttpContext context) { throw null; } } } +namespace Microsoft.Extensions.DependencyInjection +{ + public static partial class ExceptionHandlerServiceCollectionExtensions + { + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddExceptionHandler(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddExceptionHandler(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) where TService : class { throw null; } + } +} diff --git a/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerServiceCollectionExtensions.cs b/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerServiceCollectionExtensions.cs new file mode 100644 index 0000000000..fd48c73aee --- /dev/null +++ b/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerServiceCollectionExtensions.cs @@ -0,0 +1,55 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Builder; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Extension methods for the exception handler middleware. + /// + public static class ExceptionHandlerServiceCollectionExtensions + { + /// + /// Adds services and options for the exception handler middleware. + /// + /// The for adding services. + /// A delegate to configure the . + /// + public static IServiceCollection AddExceptionHandler(this IServiceCollection services, Action configureOptions) + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + return services.Configure(configureOptions); + } + + /// + /// Adds services and options for the exception handler middleware. + /// + /// The for adding services. + /// A delegate to configure the . + /// + public static IServiceCollection AddExceptionHandler(this IServiceCollection services, Action configureOptions) where TService : class + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + services.AddOptions().Configure(configureOptions); + return services; + } + } +} diff --git a/src/Middleware/Diagnostics/src/Resources.resx b/src/Middleware/Diagnostics/src/Resources.resx index a45c81ad7e..6e62f49494 100644 --- a/src/Middleware/Diagnostics/src/Resources.resx +++ b/src/Middleware/Diagnostics/src/Resources.resx @@ -248,7 +248,7 @@ Environment: - An error occurred when configuring the exception handler middleware. Either the 'ExceptionHandlingPath' or the 'ExceptionHandler' property must be set in 'UseExceptionHandler()'. Alternatively, set one of the aforementioned properties in 'Startup.ConfigureServices' as follows: 'services.Configure<ExceptionHandlerOptions>(options => { ... });'. + An error occurred when configuring the exception handler middleware. Either the 'ExceptionHandlingPath' or the 'ExceptionHandler' property must be set in 'UseExceptionHandler()'. Alternatively, set one of the aforementioned properties in 'Startup.ConfigureServices' as follows: 'services.AddExceptionHandler(options => { ... });'. No route values. diff --git a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs index da5c6c60d1..9633336ecc 100644 --- a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs +++ b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs @@ -408,7 +408,7 @@ namespace Microsoft.AspNetCore.Diagnostics // Assert Assert.Equal("An error occurred when configuring the exception handler middleware. " + "Either the 'ExceptionHandlingPath' or the 'ExceptionHandler' property must be set in 'UseExceptionHandler()'. " + - "Alternatively, set one of the aforementioned properties in 'Startup.ConfigureServices' as follows: 'services.Configure(options => { ... });'.", + "Alternatively, set one of the aforementioned properties in 'Startup.ConfigureServices' as follows: 'services.AddExceptionHandler(options => { ... });'.", exception.Message); } } diff --git a/src/Middleware/Localization/ref/Microsoft.AspNetCore.Localization.netcoreapp.cs b/src/Middleware/Localization/ref/Microsoft.AspNetCore.Localization.netcoreapp.cs index c11d47ab7b..2af40b564f 100644 --- a/src/Middleware/Localization/ref/Microsoft.AspNetCore.Localization.netcoreapp.cs +++ b/src/Middleware/Localization/ref/Microsoft.AspNetCore.Localization.netcoreapp.cs @@ -108,3 +108,11 @@ namespace Microsoft.AspNetCore.Localization public System.Threading.Tasks.Task Invoke(Microsoft.AspNetCore.Http.HttpContext context) { throw null; } } } +namespace Microsoft.Extensions.DependencyInjection +{ + public static partial class RequestLocalizationServiceCollectionExtensions + { + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddRequestLocalization(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddRequestLocalization(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) where TService : class { throw null; } + } +} diff --git a/src/Middleware/Localization/src/RequestLocalizationServiceCollectionExtensions.cs b/src/Middleware/Localization/src/RequestLocalizationServiceCollectionExtensions.cs new file mode 100644 index 0000000000..d261ab7b07 --- /dev/null +++ b/src/Middleware/Localization/src/RequestLocalizationServiceCollectionExtensions.cs @@ -0,0 +1,55 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Builder; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Extension methods for the request localization middleware. + /// + public static class RequestLocalizationServiceCollectionExtensions + { + /// + /// Adds services and options for the request localization middleware. + /// + /// The for adding services. + /// A delegate to configure the . + /// + public static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action configureOptions) + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + return services.Configure(configureOptions); + } + + /// + /// Adds services and options for the request localization middleware. + /// + /// The for adding services. + /// A delegate to configure the . + /// + public static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action configureOptions) where TService : class + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + services.AddOptions().Configure(configureOptions); + return services; + } + } +} diff --git a/src/Security/CookiePolicy/ref/Microsoft.AspNetCore.CookiePolicy.netcoreapp.cs b/src/Security/CookiePolicy/ref/Microsoft.AspNetCore.CookiePolicy.netcoreapp.cs index bd378bd871..3853f8e956 100644 --- a/src/Security/CookiePolicy/ref/Microsoft.AspNetCore.CookiePolicy.netcoreapp.cs +++ b/src/Security/CookiePolicy/ref/Microsoft.AspNetCore.CookiePolicy.netcoreapp.cs @@ -56,3 +56,11 @@ namespace Microsoft.AspNetCore.CookiePolicy Always = 1, } } +namespace Microsoft.Extensions.DependencyInjection +{ + public static partial class CookiePolicyServiceCollectionExtensions + { + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddCookiePolicy(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddCookiePolicy(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) where TService : class { throw null; } + } +} diff --git a/src/Security/CookiePolicy/src/CookiePolicyServiceCollectionExtensions.cs b/src/Security/CookiePolicy/src/CookiePolicyServiceCollectionExtensions.cs new file mode 100644 index 0000000000..3358d521e3 --- /dev/null +++ b/src/Security/CookiePolicy/src/CookiePolicyServiceCollectionExtensions.cs @@ -0,0 +1,55 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Builder; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Extension methods for the cookie policy middleware. + /// + public static class CookiePolicyServiceCollectionExtensions + { + /// + /// Adds services and options for the cookie policy middleware. + /// + /// The for adding services. + /// A delegate to configure the . + /// + public static IServiceCollection AddCookiePolicy(this IServiceCollection services, Action configureOptions) + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + return services.Configure(configureOptions); + } + + /// + /// Adds services and options for the cookie policy middleware. + /// + /// The for adding services. + /// A delegate to configure the . + /// + public static IServiceCollection AddCookiePolicy(this IServiceCollection services, Action configureOptions) where TService : class + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + services.AddOptions().Configure(configureOptions); + return services; + } + } +}