{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/13792","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/13792/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/13792/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/13792/events","html_url":"https://github.com/dotnet/roslyn/issues/13792","id":176976723,"number":13792,"title":"Feature Request: Interface instantiation and Interface ctors","user":{"login":"mwwhited","id":1729979,"avatar_url":"https://avatars.githubusercontent.com/u/1729979?v=3","gravatar_id":"","url":"https://api.github.com/users/mwwhited","html_url":"https://github.com/mwwhited","followers_url":"https://api.github.com/users/mwwhited/followers","following_url":"https://api.github.com/users/mwwhited/following{/other_user}","gists_url":"https://api.github.com/users/mwwhited/gists{/gist_id}","starred_url":"https://api.github.com/users/mwwhited/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwwhited/subscriptions","organizations_url":"https://api.github.com/users/mwwhited/orgs","repos_url":"https://api.github.com/users/mwwhited/repos","events_url":"https://api.github.com/users/mwwhited/events{/privacy}","received_events_url":"https://api.github.com/users/mwwhited/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-09-14T17:58:36Z","updated_at":"2016-09-15T09:42:36Z","closed_at":null,"body":"**Feature Request:** Interface instantiation and Interface ctors\r\n\r\nIn this new dependency injection world it would be really nice to be able to instantiate an interface.  The idea would the `new IMyInterface` would be replaced with either a standard service locator or a type resolve event that could be handled by your favorite IOC container.  \r\n\r\nIt would be even more amazing to have abstract constructors for interfaces as this would be great with generics. \r\n\r\n\r\n```\r\npublic interface IMyInterface \r\n{\r\n    IMyInterface();\r\n    IMyInterface(Type1 obj1, Type2 obj2);\r\n}\r\n\r\npublic class MyObject : IMyInterface \r\n{\r\n    private Type1 Prop1 {get;set;}\r\n    private Type2 Prop2 {get;set;}\r\n\r\n    public MyObject() \r\n    {\r\n    }\r\n\r\n    public MyObject(Type1 obj1, Type2 obj2) \r\n    {\r\n        this.Type1 = obj1;\r\n        this.Type2 = obj2;\r\n    }\r\n\r\n}\r\n\r\npublic class MyFactory \r\n{\r\n    public T myAbstractFactory.GetObject<T>(Type1 obj1, Type2 obj2) where T : IMyInterface\r\n    {\r\n        return new T(obj1, obj2);\r\n    }\r\n}\r\n\r\npublic class MyInterfaceResolver : IInterfaceResolver\r\n{\r\n    private MyFactory Factory {get} = new MyFactory();\r\n\r\n    public I Resolve<I>() where I : interface\r\n    {\r\n        return MyIOC.Resolve<I>();\r\n    }\r\n\r\n    public I Resolve<T>(Type1 obj1, Type2 obj2) where T : new(Type1, Type2)\r\n    {\r\n        return this.Factory.GetObject<I>(obj1, obj2);\r\n    }\r\n}\r\n\r\npublic class Program\r\n{\r\n    static void Main() \r\n    {\r\n        Assemby.ResolveInterfaceResolve = new MyInterfaceResolver();\r\n\r\n        // this would return new instance of MyObject\r\n        var myObject = new IMyInterface(); \r\n\r\n        // this would return new instance of MyObject \r\n        var myObject2 = new IMyInterface(new Type1(), new Type2()); \r\n\r\n        //intellisense for both myObject and myObject2 would be of type IMyInterface\r\n    }\r\n}\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/247283446","html_url":"https://github.com/dotnet/roslyn/issues/13792#issuecomment-247283446","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/13792","id":247283446,"user":{"login":"dsaf","id":3845650,"avatar_url":"https://avatars.githubusercontent.com/u/3845650?v=3","gravatar_id":"","url":"https://api.github.com/users/dsaf","html_url":"https://github.com/dsaf","followers_url":"https://api.github.com/users/dsaf/followers","following_url":"https://api.github.com/users/dsaf/following{/other_user}","gists_url":"https://api.github.com/users/dsaf/gists{/gist_id}","starred_url":"https://api.github.com/users/dsaf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsaf/subscriptions","organizations_url":"https://api.github.com/users/dsaf/orgs","repos_url":"https://api.github.com/users/dsaf/repos","events_url":"https://api.github.com/users/dsaf/events{/privacy}","received_events_url":"https://api.github.com/users/dsaf/received_events","type":"User","site_admin":false},"created_at":"2016-09-15T09:42:36Z","updated_at":"2016-09-15T09:42:36Z","body":"The damage caused by IoC container preaching will take years to overcome.\r\n\r\nhttp://blog.ploeh.dk/2010/02/03/ServiceLocatorisanAnti-Pattern\r\nhttp://blog.ploeh.dk/2014/06/10/pure-di"}}
{"actor":{"display_login":"dsaf"}}