Hello,
I' am a bit stuck on a peice of design which i hope this group can help. I am new to DDD and would like an opinion on how to solve this problem.
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.
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;
}
}
I thought that if i need to inject a repository into the constructor then it will make the factory method pointless?
public class Currency
{
public Currency(IRepoistory repository)
{
}
}
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?
Thanks