{"action":"opened","issue":{"url":"https://api.github.com/repos/stripe/stripe-dotnet/issues/1104","repository_url":"https://api.github.com/repos/stripe/stripe-dotnet","labels_url":"https://api.github.com/repos/stripe/stripe-dotnet/issues/1104/labels{/name}","comments_url":"https://api.github.com/repos/stripe/stripe-dotnet/issues/1104/comments","events_url":"https://api.github.com/repos/stripe/stripe-dotnet/issues/1104/events","html_url":"https://github.com/stripe/stripe-dotnet/issues/1104","id":297788848,"number":1104,"title":"Suggestion: Services should have a real parameterless constructor","user":{"login":"slimCODE","id":13796362,"avatar_url":"https://avatars3.githubusercontent.com/u/13796362?v=4","gravatar_id":"","url":"https://api.github.com/users/slimCODE","html_url":"https://github.com/slimCODE","followers_url":"https://api.github.com/users/slimCODE/followers","following_url":"https://api.github.com/users/slimCODE/following{/other_user}","gists_url":"https://api.github.com/users/slimCODE/gists{/gist_id}","starred_url":"https://api.github.com/users/slimCODE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slimCODE/subscriptions","organizations_url":"https://api.github.com/users/slimCODE/orgs","repos_url":"https://api.github.com/users/slimCODE/repos","events_url":"https://api.github.com/users/slimCODE/events{/privacy}","received_events_url":"https://api.github.com/users/slimCODE/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-16T13:43:10Z","updated_at":"2018-02-16T13:43:10Z","closed_at":null,"author_association":"NONE","body":"Having a real parameterless constructor allows classes to be used as generic types in methods with a `where : new()` clause. A good example in the context of this library would be a service builder method that ensures only one instance of any given service is created:\r\n\r\n```csharp\r\n        private TService GetStripeService<TService>() where TService : StripeService, new()\r\n        {\r\n            var key = typeof(TService);\r\n\r\n            if (!_services.TryGetValue(key, var out service))\r\n            {\r\n                lock(_services)\r\n                {\r\n                    if (!_services.TryGetValue(key, out service))\r\n                    {\r\n                        _services[key] = service = new TService();\r\n                    }\r\n                }\r\n            }\r\n\r\n            return service as TService;\r\n        }\r\n```\r\n\r\nSince all Stripe .NET services have an optional `apiKey` parameter, replaced by `null` at compile-time, the above construction cannot be made. We have to remove the `new()` constraint and either use builders or reflection to create instances, which is less \"elegant\"."}}
{"actor":{"display_login":"slimCODE"}}