{"action":"closed","issue":{"url":"https://api.github.com/repos/aspnet/Configuration/issues/236","labels_url":"https://api.github.com/repos/aspnet/Configuration/issues/236/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Configuration/issues/236/comments","events_url":"https://api.github.com/repos/aspnet/Configuration/issues/236/events","html_url":"https://github.com/aspnet/Configuration/issues/236","id":91980803,"number":236,"title":"BCL API review: ConfigurationBinder feedback","user":{"login":"divega","id":1253414,"avatar_url":"https://avatars.githubusercontent.com/u/1253414?v=3","gravatar_id":"","url":"https://api.github.com/users/divega","html_url":"https://github.com/divega","followers_url":"https://api.github.com/users/divega/followers","following_url":"https://api.github.com/users/divega/following{/other_user}","gists_url":"https://api.github.com/users/divega/gists{/gist_id}","starred_url":"https://api.github.com/users/divega/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divega/subscriptions","organizations_url":"https://api.github.com/users/divega/orgs","repos_url":"https://api.github.com/users/divega/repos","events_url":"https://api.github.com/users/divega/events{/privacy}","received_events_url":"https://api.github.com/users/divega/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/Configuration/labels/3%20-%20Done","name":"3 - Done","color":"CCCCCC"},{"url":"https://api.github.com/repos/aspnet/Configuration/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":{"login":"HaoK","id":6537861,"avatar_url":"https://avatars.githubusercontent.com/u/6537861?v=3","gravatar_id":"","url":"https://api.github.com/users/HaoK","html_url":"https://github.com/HaoK","followers_url":"https://api.github.com/users/HaoK/followers","following_url":"https://api.github.com/users/HaoK/following{/other_user}","gists_url":"https://api.github.com/users/HaoK/gists{/gist_id}","starred_url":"https://api.github.com/users/HaoK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HaoK/subscriptions","organizations_url":"https://api.github.com/users/HaoK/orgs","repos_url":"https://api.github.com/users/HaoK/repos","events_url":"https://api.github.com/users/HaoK/events{/privacy}","received_events_url":"https://api.github.com/users/HaoK/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/aspnet/Configuration/milestones/12","html_url":"https://github.com/aspnet/Configuration/milestones/1.0.0-beta7","labels_url":"https://api.github.com/repos/aspnet/Configuration/milestones/12/labels","id":1181465,"number":12,"title":"1.0.0-beta7","description":"","creator":{"login":"muratg","id":1808428,"avatar_url":"https://avatars.githubusercontent.com/u/1808428?v=3","gravatar_id":"","url":"https://api.github.com/users/muratg","html_url":"https://github.com/muratg","followers_url":"https://api.github.com/users/muratg/followers","following_url":"https://api.github.com/users/muratg/following{/other_user}","gists_url":"https://api.github.com/users/muratg/gists{/gist_id}","starred_url":"https://api.github.com/users/muratg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muratg/subscriptions","organizations_url":"https://api.github.com/users/muratg/orgs","repos_url":"https://api.github.com/users/muratg/repos","events_url":"https://api.github.com/users/muratg/events{/privacy}","received_events_url":"https://api.github.com/users/muratg/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":5,"state":"open","created_at":"2015-06-25T18:01:11Z","updated_at":"2015-08-14T23:44:32Z","due_on":"2015-08-24T07:00:00Z","closed_at":null},"comments":17,"created_at":"2015-06-30T04:51:21Z","updated_at":"2015-08-14T23:44:32Z","closed_at":"2015-08-14T23:44:32Z","body":"The `ConfigurationBinder` static class is considered DNX specific and embodies the ability to apply configuration values from an IConfiguration to the matching properties of an instance of a simple class. It is used in the implementation of Options.\r\n\r\nCurrently there are two public Bind methods in it:\r\n\r\n``` C#\r\npublic static TModel Bind<TModel>(IConfiguration configuration) where TModel : new()\r\n\r\npublic static void Bind(object model, IConfiguration configuration)\r\n```\r\n\r\nThe methods have different purposes, e.g. the generic version will create an object of type TModel while the no-generic one receives the object. The implementation of the latter no-ops if the objects passed is null.\r\n\r\nWe want to rationalize this API, including revisiting the names of the class and methods and also the signatures and the behavior of the methods. After gathering feedback from the BCL team and then having some discussions on our own we have come up with this API:\r\n\r\n``` C#\r\npublic static TModel Bind<TModel>(this IConfiguration configuration) where TModel : class, new()\r\npublic static TModel Bind<TModel>(this IConfiguration configuration, TModel model)  where TModel : class\r\n\r\n// Usage:\r\n\r\nvar orgSettings = configuration.GetSection(\"Org\").Bind<OrgSettings>();\r\nvar tenantSettings = configuration.GetSection(\"Tenant1\").Bind(new AppSettings());\r\n``` \r\n\r\nNotice that:\r\n1. Bind overloads are extension methods on configuration \r\n2. They return the instance of TModel, regarless of whether it got passed or created by the call. \r\n3. They don't support structs.\r\n4. The overloads that take a TModel argument should throw if a null model is passed."}}