title: How do I correctly use Unity to pass a ConnectionString to my repository classes?
body: <p>I've literally just started using the Unity Application Blocks Dependency Injection library from Microsoft, and I've come unstuck.</p>
  
  <p>This is my IoC class that'll handle the instantiation of my concrete classes to their interface types (so I don't have to keep called Resolve on the IoC container each time I want a repository in my controller):</p>
  
  <pre><code>public class IoC
  {
      public static void Intialise(UnityConfigurationSection section, string connectionString)
      {
          _connectionString = connectionString;
          _container = new UnityContainer();
          section.Configure(_container);
      }
  
      private static IUnityContainer _container;
      private static string _connectionString;
  
      public static IMovementRepository MovementRepository
      {
          get { return _container.Resolve&lt;IMovementRepository&gt;(); }
      }
  }
  </code></pre>
  
  <p>So, the idea is that from my Controller, I can just do the following:</p>
  
  <pre><code>_repository = IoC.MovementRepository;
  </code></pre>
  
  <p>I am currently getting the error:</p>
  
  <blockquote>
    <p>Exception is:
    InvalidOperationException - The type
    String cannot be constructed. You must
    configure the container to supply this
    value.</p>
  </blockquote>
  
  <p>Now, I'm assuming this is because my mapped concrete implementation requires a single string parameter for its constructor. The concrete class is as follows:</p>
  
  <pre><code>public sealed class MovementRepository : Repository, IMovementRepository
  {
      public MovementRepository(string connectionString) : base(connectionString) { }
  }
  </code></pre>
  
  <p>Which inherits from:</p>
  
  <pre><code>public abstract class Repository
  {
      public Repository(string connectionString)
      {
          _connectionString = connectionString;
      }
  
      public virtual string ConnectionString
      {
          get { return _connectionString; }
      }
      private readonly string _connectionString;
  }
  </code></pre>
  
  <p>Now, am I doing this the correct way? Should I not have a constructor in my concrete implementation of a loosely coupled type? I.e. should I remove the constructor and just make the ConnectionString property a Get/Set so I can do the following:</p>
  
  <pre><code>public static IMovementRepository MovementRepository
  {
     get
     {
        return _container.Resolve&lt;IMovementRepository&gt;(
           new ParameterOverrides
           {
              { 
                 "ConnectionString", _connectionString 
              }
           }.OnType&lt;IMovementRepository&gt;() );
     }
  }
  </code></pre>
  
  <p>So, I basically wish to know how to get my connection string to my concrete type in the correct way that matches the IoC rules and keeps my Controller and concrete repositories loosely coupled so I can easily change the DataSource at a later date.</p>
  
  <p><strong>EDIT 09:52:</strong></p>
  
  <p>Just to re-iterate what I'm after. I want to know the correct way to pass the ConnectionString or an IRepositoryConfiguration object (prefer that idea, thanks Mc) to a concrete class from Unity. I'm not too fussed on what I pass, just how I pass it whilst maintaining loose coupling.</p>