?

Log in

Previous Entry | Next Entry

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
    goal.
    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.

Solution: - Move concrete type creating power to some external source. In short Business class won’t directly create FileLogger object rather someone else will does that and give it to business logic. This is called Inversion of control. Control of object creating is given to someone else.

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
Copy right www.questpond.com

Comments

Buy 600+ Real Time Interview Videos

Call +91-22-66752917 or mail us on questpond@questpond.com for more details on C#, .NET, ASP.NET, SQL Server interview question videos.

SQL Server interview question videos

Latest Month

January 2017
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    

Tags

Powered by LiveJournal.com