Share via


MvcServiceCollectionExtensions.AddControllers Method

Definition

Overloads

AddControllers(IServiceCollection)

Adds services for controllers to the specified IServiceCollection. This method will not register services used for views or pages.

AddControllers(IServiceCollection, Action<MvcOptions>)

Adds services for controllers to the specified IServiceCollection. This method will not register services used for views or pages.

AddControllers(IServiceCollection)

Source:
MvcServiceCollectionExtensions.cs

Adds services for controllers to the specified IServiceCollection. This method will not register services used for views or pages.

public static Microsoft.Extensions.DependencyInjection.IMvcBuilder AddControllers (this Microsoft.Extensions.DependencyInjection.IServiceCollection services);
static member AddControllers : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IMvcBuilder
<Extension()>
Public Function AddControllers (services As IServiceCollection) As IMvcBuilder

Parameters

services
IServiceCollection

The IServiceCollection to add services to.

Returns

An IMvcBuilder that can be used to further configure the MVC services.

Remarks

This method configures the MVC services for the commonly used features with controllers for an API. This combines the effects of AddMvcCore(IServiceCollection), AddApiExplorer(IMvcCoreBuilder), AddAuthorization(IMvcCoreBuilder), AddCors(IMvcCoreBuilder), AddDataAnnotations(IMvcCoreBuilder), and AddFormatterMappings(IMvcCoreBuilder).

To add services for controllers with views call AddControllersWithViews(IServiceCollection) on the resulting builder.

To add services for pages call AddRazorPages(IServiceCollection) on the resulting builder.

Applies to

AddControllers(IServiceCollection, Action<MvcOptions>)

Source:
MvcServiceCollectionExtensions.cs

Adds services for controllers to the specified IServiceCollection. This method will not register services used for views or pages.

public static Microsoft.Extensions.DependencyInjection.IMvcBuilder AddControllers (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.AspNetCore.Mvc.MvcOptions> configure);
public static Microsoft.Extensions.DependencyInjection.IMvcBuilder AddControllers (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.AspNetCore.Mvc.MvcOptions>? configure);
static member AddControllers : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<Microsoft.AspNetCore.Mvc.MvcOptions> -> Microsoft.Extensions.DependencyInjection.IMvcBuilder
<Extension()>
Public Function AddControllers (services As IServiceCollection, configure As Action(Of MvcOptions)) As IMvcBuilder

Parameters

services
IServiceCollection

The IServiceCollection to add services to.

configure
Action<MvcOptions>

An Action<T> to configure the provided MvcOptions.

Returns

An IMvcBuilder that can be used to further configure the MVC services.

Remarks

This method configures the MVC services for the commonly used features with controllers for an API. This combines the effects of AddMvcCore(IServiceCollection), AddApiExplorer(IMvcCoreBuilder), AddAuthorization(IMvcCoreBuilder), AddCors(IMvcCoreBuilder), AddDataAnnotations(IMvcCoreBuilder), and AddFormatterMappings(IMvcCoreBuilder).

To add services for controllers with views call AddControllersWithViews(IServiceCollection) on the resulting builder.

To add services for pages call AddRazorPages(IServiceCollection) on the resulting builder.

Applies to