Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C#

Inversion of Control: Overview with Examples

Rate me:
Please Sign up or sign in to vote.
4.70/5 (27 votes)
8 May 2012CPOL7 min read 126.3K   955   52  
This article discusses the basic concepts of IoC, how to achieve it, and Dependency Injections.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IoCSample.Constructor_Dependency_Injection
{
    public class LoggingEngine
    {
        private ILogger logger = null;

        public LoggingEngine(ILogger logger)
        {
            this.logger = logger;
        }

        public void Log(string message)
        {
            logger.OpenLog();
            logger.Log(message);
            logger.CloseLog();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Automation Anywhere Inc.
India India
I am Himanshu Manjarawala, Garduate in Computer Science and MCA From Veer Narmad South Gujarat University, Surat Gijarat India. Currently working as Sr. Software Developer in Automation Anywhere Softwares Pvt. Ltd. Vadodara, Gujarat

Comments and Discussions