Help getting DI/IoC in house
Asked Answered
G

2

7

I am trying to introduce DI/IoC programming methodology into our development group, but one of the developer asked the following question:

Why do we need it? Is there any concrete example that can show me the benefit of using DI/IoC framework like windsor castle?

Therefore, I am asking if there are any case study or article out there that prove DI/IoC can benefit in a enterprise-level .NET website?

Thanks in advance

Update: I am aware of all the benefit of DI/IoC brings, but I have yet to see a complete example on the web that goes through a entire process of creating a app utilizing DI/IoC and benefit from it. Again, any article or links would be appreciated.

Geronto answered 10/9, 2009 at 4:10 Comment(2)
I'd be as wary as that developer if you were trying to introduce a programming methodology to my project and couldn't answer that question.Infect
Agreed with Josh, if it sounds & looks like snake oil, it probably is... (unless it's me trying to teach TDD to the team, LOL)Nucleo
F
6

I'm working on a project where I can see at least three benefits to Dependency Injection and Inversion of Control:

  1. The flexibility DI and, to a lesser extent, IoC allow as it pertains to unit testing. We can zero in on a particular aspect of code (or system under test) and test this bit of functionality without needing to prep a database table or be subject to the whims of sections of code we're not concerned with at the moment.

  2. Injecting dependencies via IoC is a fairly seamless, automatic thing, and it allows people to work on logic without requiring that the underlying support classes are complete. For example, I can write a web page that shows a list of users without having written any code to retrieve that information from the database. That can be written by someone else, possibly in parallel, so more work can get done in less time.

  3. On one of my current projects, I want to have the ability to demo the web user interface and back-end processing to one of the stakeholders. This is made so much easier by DI and IoC because I can have a collection of fakes that supply the exact data I need to conduct the demo. This way, I'm not freaking out the day before with making sure database tables are populated the way I expect them to be.

DI encourages a loose coupling between a particular class and its dependencies, while IoC allows us to dynamically configure which implementations of these dependencies are injected into classes that use them. The latter is important with respect to #3, because my web application will most be configred with IoC based on settings I've made to the web.config file. I will need to change only that file when we go to production and begin to use non-fake classes.

Frederico answered 10/9, 2009 at 4:17 Comment(0)
M
6

To name the few particular benefits:

  • Cleaner code, that carries the essence of your business logic in it, not the infrastructural thickness
  • DI allows you to create more modular applications by providing a mechanism for decoupling your app layers
  • IoC allows to externalize application wiring/bootstrapping and provides centralized(sort of) resource management(to some extent). Implication - you have more time to concentrate on the actual functionality/business logic

Some good info about IoC and DI can be read here: http://www.theserverside.com/tt/articles/article.tss?l=IntrotoSpring25

Granted it is about Spring Framework, general DI concepts still apply.

Miele answered 10/9, 2009 at 4:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.