{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Configuration/issues/365","labels_url":"https://api.github.com/repos/aspnet/Configuration/issues/365/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Configuration/issues/365/comments","events_url":"https://api.github.com/repos/aspnet/Configuration/issues/365/events","html_url":"https://github.com/aspnet/Configuration/issues/365","id":125299810,"number":365,"title":"services.Configure<TOptions>(Configuration) doesn't load properties in the type name section when binding to configuration.","user":{"login":"BellaCode","id":1168155,"avatar_url":"https://avatars.githubusercontent.com/u/1168155?v=3","gravatar_id":"","url":"https://api.github.com/users/BellaCode","html_url":"https://github.com/BellaCode","followers_url":"https://api.github.com/users/BellaCode/followers","following_url":"https://api.github.com/users/BellaCode/following{/other_user}","gists_url":"https://api.github.com/users/BellaCode/gists{/gist_id}","starred_url":"https://api.github.com/users/BellaCode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BellaCode/subscriptions","organizations_url":"https://api.github.com/users/BellaCode/orgs","repos_url":"https://api.github.com/users/BellaCode/repos","events_url":"https://api.github.com/users/BellaCode/events{/privacy}","received_events_url":"https://api.github.com/users/BellaCode/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-07T01:08:02Z","updated_at":"2016-01-07T16:29:03Z","closed_at":null,"body":"I followed the example MyOptions approach documented at http://docs.asp.net/en/latest/fundamentals/configuration.html#options-example\r\n\r\n**Issue**\r\nI removed the Action approach and found that the configuration binding approach does not work as described.\r\n\r\nIf I created this in the appsettings.json, the value doesn't get loaded:\r\n\"MyOptions\": {\r\n    \"Option1\": \"MyValue\"\r\n  },\r\n\r\nIf I just put this in the configuration at the root of appsettings.json , it does get loaded:\r\n \"Option1\": \"MyValue\"\r\n\r\n**Investigation**\r\nReading through the call stack of the ConfigurationBinder.Bind() method, I found that it calls BindInstance().  BindInstance() uses the config parameter as the section.  Because the TOptions is a class, it call BindNonScalar().  BindNonScalar() looks for the property name.\r\n\r\nThere doesn't seem to be a point where the ConfigurationBinder uses the type name of the TOptions to move into that as a section, so the property values have to be at the root the application configuration.\r\n\r\n**Proposal**\r\nI'm not sure if the finding of the type name as a section should be in the ConfigureOptions method or in the ConfigurationBinder.  \r\n\r\n**Bonus**\r\nIt would be great to be able to put attributes on the MyOptions class and properties to help define the hierarchy structure for binding to the options.\r\n\r\n**Workaround**\r\nMy current workaround is to manually set the value using the Action approach (which works)."},"comment":{"url":"https://api.github.com/repos/aspnet/Configuration/issues/comments/169717107","html_url":"https://github.com/aspnet/Configuration/issues/365#issuecomment-169717107","issue_url":"https://api.github.com/repos/aspnet/Configuration/issues/365","id":169717107,"user":{"login":"BellaCode","id":1168155,"avatar_url":"https://avatars.githubusercontent.com/u/1168155?v=3","gravatar_id":"","url":"https://api.github.com/users/BellaCode","html_url":"https://github.com/BellaCode","followers_url":"https://api.github.com/users/BellaCode/followers","following_url":"https://api.github.com/users/BellaCode/following{/other_user}","gists_url":"https://api.github.com/users/BellaCode/gists{/gist_id}","starred_url":"https://api.github.com/users/BellaCode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BellaCode/subscriptions","organizations_url":"https://api.github.com/users/BellaCode/orgs","repos_url":"https://api.github.com/users/BellaCode/repos","events_url":"https://api.github.com/users/BellaCode/events{/privacy}","received_events_url":"https://api.github.com/users/BellaCode/received_events","type":"User","site_admin":false},"created_at":"2016-01-07T16:29:03Z","updated_at":"2016-01-07T16:29:03Z","body":"@divega \r\n\r\n1. Does that work for you?\r\n\r\n>> It solves the immediate problem.  I think users will still have issues when they have a nested hierarchy of JSON and want to map that into an object.  Convention would allow for property names to match up, but attribution could provide control over the mapping.\r\n\r\n2. Was there anything else in the docs that made you think Configure would automatically select a subsection based on the name of the type passed?\r\n\r\n>> Yes.  This section implied that the MyOptions and Option1 parts would be used.\r\n\r\n\"When you bind options to configuration each property in your options type is bound to a configuration key of the form property:subproperty:.... For example, the MyOptions.Option1 property is bound to the key Option1, which is read from the option1 property in appsettings.json. Note that configuration keys are case insensitive.\""}}