4 ms·
Do a lot of people use DI? I thought that was all a bit of a fad like factories. Lots of extra code for little benefit. Especially in a statically typed langua
by mattmanser 11y ago
Do a lot of people use DI?
I thought that was all a bit of a fad like factories. Lots of extra code for little benefit. Especially in a statically typed language like C# where it gets rid of so many of the benefits of using it as a language.
- jenscow 11y agoYep. You can't see the Emperor's clothes, either?
- wdmeldon 11y agoIn the .NET/Enterprise world, absolutely.
- briHass 11y agoHow does it remove anything beneficial? I look at DI, or really the dependency inversion pattern, as a guard that encourages better/more maintainable code. Can you write good code without it, sure, and you can write bad code with it, but it's much more likely that code written with it is easier to trace and maintain. Not to mention much easier to test. The configuration based, hot-swapping of dependencies...that I've never seen much need for even in larger projects.
- deleted 11y ago[deleted]
- briHass 11y agoSince this is a C# thread, there are a number of ways to navigate through the interface to the implementation in Visual Studio: 1. Right-click, Go To Implementation (Ctrl-F12) 2. Right-click, Find All References (shows the interface and impl) 3. (Resharper) Navigate, Dervived Symbols (Alt-End) Even the new method info in Visual Studio 2015 (2013 Enterprise) is able count and show you the usages as a tip through the interface. I don't experience any issues with this pattern; the tooling is built around it.
- rjbwork 11y ago4. There's a plugin for ReSharper called Agent Mulder that examines your AutoFac configuration and knows when something is registered and can take you right to it.
- yareally 11y ago> Do a lot of people use DI? I use it mostly for unit testing.
- guiomie 11y agoDI usually means Dependency Injection, and I don't see how I could do unit testing/mocking without DI (especially constructor based DI). IoC containers such as AutoFac, those are from my perspective more of a fad.
- rjbwork 11y agoWhy do you consider them a fad? I've found it immensely useful to not go through the rigamarole of newing up a ton of objects manually in my web controllers and queue/batch processing frameworks. Just choose your composition roots properly and you can easily add new endpoints/jobs/event processors without all the worry of resolving all the dependencies manually. It also allows you to reduce footprints (setting non-stateful code/configuration objects as singletons), transparently cache and instrument(dynamic proxies, or application specific caching/logging wrappers), and other similar application-level concerns without it infecting consuming code or otherwise independent modules.
- guiomie 11y agoBy fad, I meant that the frameworks change in the world of IoC, while DI is pretty much a concept easily applicable in OO languages. I myself and my team use AutoFac right now, but who knows what it could be in 1-2 years...