I've started learning asp.net core and trying to improve my c# knowledge.
I'm struggling with ConfigureServices in my startup class.
public void ConfigureMvcOptions(MvcOptions options)
{
options.EnableEndpointRouting = false;
}
public void ConfigureServices(IServiceCollection services)
{
Action<MvcOptions> options = new Action<MvcOptions>(ConfigureMvcOptions);
services.AddMvc(options);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello world");
});
}
This above is resulting in a compile error
"Warning MVC1005 Using 'UseMvcWithDefaultRoute' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvcWithDefaultRoute', please set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices'"
I can remove the error by using a Lambda expression inside the AddMvc method instead but I don't understand why this is working
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc((options) => options.EnableEndPointRouting = false);
}
The above works without a problem. I just don't understand what's wrong with my implementation of the Action delegate?