title: Unable to do property injection using Autofac
body: <p>I am new to autofac. I am trying to do property injection using this IoC container.  The following is my code. I am getting error:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object</p>
  </blockquote>
  
  <p>At this line: .
  <code>return _salary.employeeSalary</code>; in the <code>GetSalary(int employeeId)</code> method. In the Program class I even tried, <code>build.RegisterType&lt;Employee&gt;().WithProperty("_salary", new Salary{ employeeId = 5, employeeSalary = 500 });</code></p>
  
  <pre><code>public interface IEmployee
  {
      double GetSalary(int employeeId);
  }
  public interface ISalary
  {
      int employeeId { get; set; }
      double employeeSalary { get; set; }
  }
  public class Salary : ISalary
  {
      public int employeeId {get; set;}
      public double employeeSalary { get; set; }
  }
  
  public class Employee: IEmployee
  {
      public ISalary _salary;        
  
      public double GetSalary(int employeeId)
      {
          if (employeeId == 5)
          {
              return _salary.employeeSalary;
          }
          else
          {
              return 0;
          }
      }
  }
  
  public class Program
   {
       static void Main(string[] args)
       {
           var build = new ContainerBuilder();
           build.RegisterType&lt;Salary&gt;().As&lt;ISalary&gt;();
           build.RegisterType&lt;Salary&gt;().As&lt;ISalary&gt;().PropertiesAutowired();               
           var container = build.Build();
           Employee employee = container.Resolve&lt;Employee&gt;();
  
           Console.WriteLine(employee.GetSalary(5));
           Console.ReadLine();            
       }
  }
  </code></pre>