mardi 26 avril 2016

how to register parameterized based constructor classes in unity container in C#?

I am new to Dependency injection Pattern. Please look in to the below scenario. Right now, my below code is in tightly coupled. I want to make this as lightly coupled.

Could someone help me out to implement dependency injection using Unity?

// Implementation of class A
    public class A
    {
      public B b{get;set;}
      public A(B b,string c)
      {
         this.b=b;
         this.A(b,c);
      }
    }

//Implementation of Class B
    public class B
    {
        public int value1 {get;private set;}
        public string stringValue {get;private set;}

        public B(int value,string strValue)
        {
           this.value1=value;
           this.stringValue=strValue;
        }
    }

    //Implementation of class C
    public class C
    {

      public void Dosomething()
      {
         B b=null;
         string value="Something";
         A a=new A(b,value); // Here I need to implement unity to resolve tight coupling without creating object of Class A

      }
    }

Aucun commentaire:

Enregistrer un commentaire