Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup Code changes in MVC #62

Open
rynowak opened this issue Sep 2, 2015 · 1 comment
Open

Startup Code changes in MVC #62

rynowak opened this issue Sep 2, 2015 · 1 comment

Comments

@rynowak
Copy link
Member

rynowak commented Sep 2, 2015

For beta7 we've changed MVC's startup code APIs to be more consistent with EntityFramework and Identity.

Part 1:

Both the AddMvc(...) and AddMvcCore(...) extension methods now return a builder API, which can be chained to additional setup methods:

services.AddMvc(options =>
{
    options.Filters.Add(...);
})
.AddXmlDataContractSerializerFormatters()
.AddViewLocalization(LanguageViewLocationExpanderFormat.SubFolder);

Or used as local variable:

var mvc = services.AddMvc(options =>
{
    options.Filters.Add(...);
})
mvc.AddXmlDataContractSerializerFormatters()
mvc.AddViewLocalization(LanguageViewLocationExpanderFormat.SubFolder);

The purpose of this change (beyond consistency) is to make the intellisense experience more targeted. Now MVC methods that require you to register MVC can't be called without doing so. Also MVC's various features are more discoverable if you're looking at intellisense for the builder.

Part 2:

We removed additional extension methods that we had off of IServiceCollection or MvcOptions and made them into extensions methods targeting one of the MVC builders (IMvcCoreBuilder or IMvcBuilder).

Old:
services.AddMvc();
services.ConfigureMvc(options =>
{
    options.AddXmlDataContractSerializerFormatters();
})
New:
services.AddMvc().AddXmlDataContractSerializerFormatters();

Part 3:

We removed variations on ConfigureMvcXyz(...) and replaced them with extension methods targeting one of the builders.

All of our AddXyzFeature(...) methods that have an associated options type, we provide an overload that takes an Action<T> for configuring options.

Where there's no obvious AddXyzFeature(...) we provide an AddXyzOptions(...) method instead.

Old:
services.ConfigureMvcJson(...);
New:
services.AddMvc().AddJsonOptions(...);
@rynowak rynowak added this to the 1.0.0-beta7 milestone Sep 2, 2015
@aspnet aspnet locked and limited conversation to collaborators Sep 2, 2015
@rynowak
Copy link
Member Author

rynowak commented Sep 2, 2015

For discussion and feedback, please see the related discussion issue aspnet/Mvc#3083

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant