title: Dependency injection of context class in constructor
body: <p>I have a service that uses <code>ApplicationContext</code>. So I want to use dependency injection to have the application give me the context. So I put in in the construction </p>
  
  <pre><code>Private _context;
  
  // Constructor
  public Service(ApplicationContext context) {
      _context = context
  }
  </code></pre>
  
  <p>The problem is when I initialize this service I have to pass it a context so that's not really dependency injection is it? </p>
  
  <p>Is there a way to get the context injected without putting it in the constructors parameters?</p>
  
  <p>****** EDIT *****</p>
  
  <p>I'm sorry that I didn't give enough information the first time. Let me try and explain it better. I have a service which i will just call service for now. It reads the header variables in a request and return xml base on their values. I newup an instance in each different method of a controller as they may have different values for the header variables. I would like the context injected into the service instead of the controller so i can say this:</p>
  
  <pre><code>Service service = new Service(Request);
  </code></pre>
  
  <p>Instead of this:</p>
  
  <pre><code>Service service = new Service(Request, Context);
  </code></pre>
  
  <p>The reason being the service is doing all the work with the context the controller need not know anything about it. The code I have will work but it would be great if i could get this working the way i explained.</p>
  
  <p>If we could still <code>[FromServices]</code> on a property. That would be the perfect solution. Unfortunately that was taken away. Which would only leave injecting the context into the constructor for either the service or the controller. In which case I would still have to pass the context as an argument to the service. </p>
  
  <p>Is there a way to inject the context into the services constructor and avoid having to pass it as an argument upon creation?</p>
  
  <p>There may be a more elegant solutions which I would be happy to consider. </p>