Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

QuestPond’s Interview Questions & Answers on Inversion of Control (IOC) in .NET

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
Tags: .net interview questions, .net step by step training, .net training, csharp interview questions, inversion of control (ioc), it interview questions with answers, programming interview questions
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments