I am beginner in dependency injection.I used Microsoft Unity in console application to start with and to brush up basics. All I wanted to call method of Addition Class or Substraction Class based on the class I register to interface reference. But I am getting refernce InterfaceReference as null. Please suggest where I am doing wrong in below case ?
I used one interfacer -
namespace ConsoleApplication3
{
interface IArithmetic
{
int DoOperation(int a, int b);
}
}
And 2 claess -
namespace ConsoleApplication3
{
class Addition : IArithmetic
{
public int DoOperation(int a, int b)
{
return a + b;
}
}
}
namespace ConsoleApplication3
{
class Substraction : IArithmetic
{
public int DoOperation(int a, int b)
{
return a - b;
}
}
}
namespace ConsoleApplication3
{
class Program
{
private static IArithmetic InterfaceReference;
public Program(IArithmetic InterfaceReferenceParam)
{
InterfaceReference = InterfaceReferenceParam;
}
static void Main(string[] args)
{
IUnityContainer myContainer = new UnityContainer();
myContainer.RegisterType<IArithmetic, Addition>();
int output = InterfaceReference.DoOperation(5, 2);
Console.Write(output);
Console.WriteLine();
}
}
}