TheSharperDev

Educating about C# and F#

.Net Core 3.0 AddControllers() Method

In case you haven’t heard, .Net Core 3.0 has now been released! So many things are now available as part of this release.

I feel like I could just keep going on and on.

With all those changes, one small thing I’m glad to see is the addition of a AddControllers() method in the Startup.cs file.

.Net Core 2.2 And Before

I consider myself an API developer. A lot of times when I want to work with C# I create an API project using the following command.

dotnet new webapi

Then if you open up the Startup.cs file you would see something similar to this:

AddMvc()? I created a webapi project but now I have an Mvc dependencies? Why is that?

That always confused me. I know you’re able to manually pick the right dependencies, but why is this the default experience?

.Net Core 3.0

However, if you download .Net Core 3.0 and create the same project, this is now what you’ll see.

Now I’m only including the dependencies that I really need for my project. So much better!

No changes have been made to the AddMvc() method, so if you need Mvc support by all means keep using it.

Closing Thoughts

I’m obviously very excited about a lot of the new 3.0 features, but sometimes it’s small changes like this that really have me looking forward to the future of .Net.