What is Inversion of Control (IOC) and why it is required?In order to understand Inversion of control let’s talk about a scenario.
Scenario: - We have Customer_Business_Logic class which is using FileLogger class internally for logging Exception inside file.
Understanding problems with this approach–
- Now let’s say some time later our organization asks us to replace FileLogger with DBLogger
so that error can be logged inside Database instead of File. In this case we
will explicitly change the code written inside Business logic layer to achieve
Changes in the business logic may leads to error in business logic.
- Testing of business logic in isolation is not possible because it is directly referencing FileLogger class.
- FileLogger need to be available at compile time. Means we can start working on Business logic only after FileLogger is created.
How to implement Inversion of Control (IOC)?IOC or Inversion control can be implemented using many ways like Factory Pattern, Dependency injection, Service Locator Pattern etc.
For technical trainings on various topics like WCF (Windows Communication Foundation), MVC (Model View Controller), Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com
For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla
See the following video on real time scenarios on Dependency Injection and Inversion of Control (DIIOC): -
Click and see here for more learning Inversion of Control(IOC) in .NET