From 12f33de92c34679e279e8f4f9dcfe02ca7a9bcff Mon Sep 17 00:00:00 2001 From: jacalvar Date: Thu, 25 Feb 2016 12:32:41 -0800 Subject: [PATCH] Make ServiceCollectionExtensions consistent --- .../DependencyInjection/IMvcBuilder.cs | 6 +++ .../DependencyInjection/IMvcCoreBuilder.cs | 6 +++ .../MvcCoreServiceCollectionExtensions.cs | 32 ++++++++++---- .../Internal/MvcBuilder.cs | 8 ++++ .../Internal/MvcCoreBuilder.cs | 8 ++++ .../MvcServiceCollectionExtensions.cs | 44 ++++++++++--------- 6 files changed, 76 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcBuilder.cs b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcBuilder.cs index 13994db34d..5e12b9da62 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcBuilder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcBuilder.cs @@ -3,8 +3,14 @@ namespace Microsoft.Extensions.DependencyInjection { + /// + /// An interface for configuring MVC services. + /// public interface IMvcBuilder { + /// + /// Gets the where MVC services are configured. + /// IServiceCollection Services { get; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcCoreBuilder.cs b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcCoreBuilder.cs index 02e0751a66..4c621afe1b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcCoreBuilder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcCoreBuilder.cs @@ -3,8 +3,14 @@ namespace Microsoft.Extensions.DependencyInjection { + /// + /// An interface for configuring essential MVC services. + /// public interface IMvcCoreBuilder { + /// + /// Gets the where essential MVC services are configured. + /// IServiceCollection Services { get; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs index 9f01cd034c..b0454b4410 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs @@ -22,8 +22,16 @@ using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.Extensions.DependencyInjection { + /// + /// Extension methods for setting up essential MVC services in an . + /// public static class MvcCoreServiceCollectionExtensions { + /// + /// Adds essential MVC services to the specified . + /// + /// The to add services to. + /// An that can be used to further configure the MVC services. public static IMvcCoreBuilder AddMvcCore(this IServiceCollection services) { if (services == null) @@ -31,9 +39,18 @@ namespace Microsoft.Extensions.DependencyInjection throw new ArgumentNullException(nameof(services)); } - return AddMvcCore(services, setupAction: null); + ConfigureDefaultServices(services); + AddMvcCoreServices(services); + + return new MvcCoreBuilder(services); } + /// + /// Adds essential MVC services to the specified . + /// + /// The to add services to. + /// An to configure the provided . + /// An that can be used to further configure the MVC services. public static IMvcCoreBuilder AddMvcCore( this IServiceCollection services, Action setupAction) @@ -43,16 +60,15 @@ namespace Microsoft.Extensions.DependencyInjection throw new ArgumentNullException(nameof(services)); } - ConfigureDefaultServices(services); - - AddMvcCoreServices(services); - - if (setupAction != null) + if (setupAction == null) { - services.Configure(setupAction); + throw new ArgumentNullException(nameof(setupAction)); } - return new MvcCoreBuilder(services); + var builder = services.AddMvcCore(); + services.Configure(setupAction); + + return builder; } // To enable unit testing diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcBuilder.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcBuilder.cs index ed25f55d29..84cc8468eb 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcBuilder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcBuilder.cs @@ -6,8 +6,15 @@ using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc.Internal { + /// + /// Allows fine grained configuration of MVC services. + /// public class MvcBuilder : IMvcBuilder { + /// + /// Initializes a new instance. + /// + /// The to add services to. public MvcBuilder(IServiceCollection services) { if (services == null) @@ -18,6 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal Services = services; } + /// public IServiceCollection Services { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreBuilder.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreBuilder.cs index 3cdef79c09..eb64507a4e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreBuilder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreBuilder.cs @@ -6,8 +6,15 @@ using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc.Internal { + /// + /// Allows fine grained configuration of essential MVC services. + /// public class MvcCoreBuilder : IMvcCoreBuilder { + /// + /// Initializes a new instance of . + /// + /// The to add services to. public MvcCoreBuilder(IServiceCollection services) { if (services == null) @@ -18,6 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal Services = services; } + /// public IServiceCollection Services { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs index 929841b652..36c876bdaa 100644 --- a/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs @@ -16,7 +16,7 @@ namespace Microsoft.Extensions.DependencyInjection /// Adds MVC services to the specified . /// /// The to add services to. - /// A reference to this instance after the operation has completed. + /// An that can be used to further configure the MVC services. public static IMvcBuilder AddMvc(this IServiceCollection services) { if (services == null) @@ -24,22 +24,6 @@ namespace Microsoft.Extensions.DependencyInjection throw new ArgumentNullException(nameof(services)); } - return AddMvc(services, setupAction: null); - } - - /// - /// Adds MVC services to the specified . - /// - /// The to add services to. - /// An action delegate to configure the provided . - /// A reference to this instance after the operation has completed. - public static IMvcBuilder AddMvc(this IServiceCollection services, Action setupAction) - { - if (services == null) - { - throw new ArgumentNullException(nameof(services)); - } - var builder = services.AddMvcCore(); builder.AddApiExplorer(); @@ -60,11 +44,31 @@ namespace Microsoft.Extensions.DependencyInjection builder.AddCors(); - if (setupAction != null) + return new MvcBuilder(builder.Services); + } + + /// + /// Adds MVC services to the specified . + /// + /// The to add services to. + /// An to configure the provided . + /// An that can be used to further configure the MVC services. + public static IMvcBuilder AddMvc(this IServiceCollection services, Action setupAction) + { + if (services == null) { - builder.Services.Configure(setupAction); + throw new ArgumentNullException(nameof(services)); } - return new MvcBuilder(services); + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + + var builder = services.AddMvc(); + builder.Services.Configure(setupAction); + + return builder; } } }