title: Dependency Injection and other constructor parameters - bad practice?
body: <p>At the moment I am experimenting a little bit with dependency injection containers, this time with Unity. </p>
  
  <p>Given the following interface:</p>
  
  <pre><code>public interface IPodcastCommService
  {
      void Download();
  
      void Upload();
  }
  </code></pre>
  
  <p>and the following implementation: </p>
  
  <pre><code>public class PodcastService
  {
       private IPodcastCommService commservice;
       private String url;
  
       public PodcastService(String url, IPodcastCommService commservice)
       {
           this.commservice = commservice;
           this.url = url;
       }
  }
  </code></pre>
  
  <p>Because of the constructor, I was looking for a solution to pass the parameter to it and found it: </p>
  
  <pre><code>var p = container.Resolve&lt;IPodcastCommService&gt;(new ParameterOverride("url", myUrl));
  </code></pre>
  
  <p>So far so good, but at the same time I read about how bad this is and how bad the design of the class is and yes, it looks a little bit ugly. But how can I pass a parameter to class in an elegant way? </p>
  
  <p>My first thought was to do it as a property, but then I have to check every time I need the Url that it is already given. </p>
  
  <p><strong>Update:</strong>
  One example, where I read that this is bad design, is this: </p>
  
  <blockquote>
    <p>But there may be cases where you have pass in custom constructor parameters for the resolve operation. Some may argue that this screams of bad architecture but there’s situations like bringing a DI-container to a legacy system which may require these kind of actions.</p>
  </blockquote>
  
  <p>Source: <a href="http://mikaelkoskinen.net/unity-passing-constructor-parameters-to-resolve/">http://mikaelkoskinen.net/unity-passing-constructor-parameters-to-resolve/</a></p>