Saturday, August 13, 2016

Microsoft MVC6 New JSON Based Configuration Tips

I have been away from the MVC world for 2 years, and just started a brand new project with it today. Things have changed quite a bit from MVC4 days. Now there is no Web.config in the base project template for Visual Studio.

After starting to learn about this change, which should be positive and there are good reasons for this change, I have found out, as usual, all the examples out there are outdated from RC times or not complete.

Here are some things I ran into that you would also run into.

You Will Need to Install Microsoft.Extensions.Options and also Microsoft.Extensions.Options.ConfigurationExtensions

If you do not do this, you will see

'Microsoft.Extensions.Configuration.IConfigurationRoot' to 'System.Action<CustomSettings>'  error.

They are available via NuGet, Just look for Microsoft.Extensions.Options and both should come up.

Where to Put My Option Plain C# Object (POCO)?

I would put that under your Models folder (create one under the root if needed), but it can be anywhere, perhaps Confgs subfolder, if you make one would just be OK too.

No comments: