Dependency injection. Why isn’t it built in?

I think that it is about time for C# to have dependency injection syntax. For example var s = serviceProvider.GetService(typeof(IMyService)) could be expressed as var s = IMyService(); Any thoughts?

Edit: Maybe I should name it the factory pattern. C# could have a default factory for object creation and user-defined factories as well. Then var s = new IMyService(); would create the object implementing IMyService interface. It would be useful for unit tests.

submitted by /u/readmond
[link] [comments]

Leave a Reply