Hi,
I have a generic function which gets a interface as a type, now in one condition I have to create a new class depending on the interface. I have been thinking about it and a way to solve it would be to use an IoC but I was hoping there would be an other way because an IoC seems a bit like an overkill.
below is an attempt using the visitor pattern:
public class RepositoryManager<T> : IRepositoryManager<T> where T : class, new()
{
public T GetOrCreate(string id)
{
T item = (T)CreateNew(new T(), id);
return item;
}
}
If instead of an interface I was getting an object then I could use the visitor pattern to figure out what class to instantiate but I can't seem to figure this out depending on the interface provided.
An other idea I had was if I can make the where declaration like an or?
public class RepositoryManager<T> : IRepositoryManager<T> where T : class, Iabc or Ixyz, new()
I hope the question is clear :)
-Mark