Skip to content

IOC DI Unity

Amit P Naik edited this page May 19, 2020 · 1 revision

Abstract Factory Pattern provides a way to encapsulate a group of individual factories that have a common theme.

In the scenario, where if there is two or more factory class with common theme (like private or public sector.

UML Diagram script from http://www.nomnoml.com/

image

[IOC]->[DI]

Solutions

client

    #region IOC DI Unity

    ConsoleColorMethod("IOC DI Unity");

    IUnityContainer container = new UnityContainer();
    container.RegisterType<IRechargeHandler, RechargeJIO>("JIO");
    container.RegisterType<IRechargeHandler, RechargeVodafone>("Vodafone");

    IRechargeHandler recharge = container.Resolve<IRechargeHandler>("JIO");
    recharge.DoRecharge();

    #endregion
namespace IOC_DI_Unity
{
    public interface IRechargeHandler
    {
        void DoRecharge();

    }
    public class RechargeJIO : IRechargeHandler
    {
        public void DoRecharge()
        {
            Console.WriteLine("Recharge for JIO is done successfully.");
        }
    }

    public class RechargeVodafone : IRechargeHandler
    {
        public void DoRecharge()
        {
            Console.WriteLine("Recharge for Vodafone is done successfully.");
        }
    }
}
Clone this wiki locally