title: DDD - Factory Method and Dependency Injection
body: <p>I'm a bit stuck on a piece of design. I am new to DDD and would like an opinion on how to solve this problem.</p>
  
  <p>I have a Currency Value Object that needs to access a repository to get addditional data to make the class complete. The problem (or design issue) is that new instances of Currency can only be created via the Factory Method.</p>
  
  <pre><code>public class Currency
  {
    internal Currency() {}
  
    public string Name { get; set; }
  
    public static Currency CreateCurrencyFromAlphaCode(string alphaCode)
    {
      Currency cur = new Currency();
      //Needs repository to set name etc
      return cur;
    }
  
    public static Currency CreateCurrencyFromCountryCode(string countryCode)
    {
      Currency cur = new Currency();
      //Needs repository to set name etc
      return cur;
    }
  
    public static Currency CreateCurrencyFromCountryName(string countryName)
    {
      Currency cur = new Currency();
      //Needs repository to set name etc
      return cur;
    }
  
  }
  </code></pre>
  
  <p>I thought that if I need to inject a repository into the constructor then it will make the factory method pointless?</p>
  
  <pre><code>public class Currency
  {
    public Currency(IRepoistory repository)
    {
  
    }
  }
  </code></pre>
  
  <p>How should I design this class, given the dependency on the repository — must I make a param on each of the Factory Methods to accept a repository?</p>