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.
Inversion of Control(IoC) is also known as Dependency injection (DI). The Spring container uses Dependency Injection (DI) to manage the components that build up an application and these objects are called Spring Beans. Spring implements DI by either an XML configuration file or annotations.
The IoC container is a framework used to manage automatic dependency injection throughout the application, so that we as programmers do not need to put more time and effort into it. There are various IoC Containers for . NET, such as Unity, Ninject, StructureMap, Autofac, etc.
Dependency Injection is the method of providing the dependencies and Inversion of Control is the end result of Dependency Injection. IoC is a design principle where the control flow of the program is inverted. Dependency Injection is one of the subtypes of the IOC principle.
An IoC container is closely related to dependency injection (DI) where you inject objects into a class instead of creating the objects inside the class. You can basically think of an IoC container as a tool that helps you do this in a more flexible and customizable way.
I'm working on a project where I can see at least three benefits to Dependency Injection and Inversion of Control:
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.
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.
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.
To name the few particular benefits:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With