// 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 System.Collections.Generic; using System.Reflection; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Internal; namespace Microsoft.Extensions.DependencyInjection { /// /// Extensions for configuring MVC using an . /// public static class MvcCoreMvcBuilderExtensions { /// /// Registers an action to configure . /// /// The . /// An . /// The . public static IMvcBuilder AddMvcOptions( this IMvcBuilder builder, Action setupAction) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (setupAction == null) { throw new ArgumentNullException(nameof(setupAction)); } builder.Services.Configure(setupAction); return builder; } public static IMvcBuilder AddFormatterMappings( this IMvcBuilder builder, Action setupAction) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (setupAction == null) { throw new ArgumentNullException(nameof(setupAction)); } builder.Services.Configure((options) => setupAction(options.FormatterMappings)); return builder; } /// /// Register the specified as services and as a source for controller /// discovery. /// /// The . /// A sequence of controller s to register in the /// and used for controller discovery. /// The . public static IMvcBuilder AddControllersAsServices( this IMvcBuilder builder, IEnumerable controllerTypes) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (controllerTypes == null) { throw new ArgumentNullException(nameof(controllerTypes)); } ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes); return builder; } /// /// Registers controller types from the specified as services and as a source /// for controller discovery. /// /// The . /// Assemblies to scan. /// The . public static IMvcBuilder AddControllersAsServices( this IMvcBuilder builder, IEnumerable controllerAssemblies) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (controllerAssemblies == null) { throw new ArgumentNullException(nameof(controllerAssemblies)); } ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies); return builder; } } }