I have a small factory near my di container. I see two ways to implement the factory:
1. private IDictionary<Type, Func<object>> _entityBuilders; public T Build<T>() => (T)_entityBuilders[typeof(T)]();
2.private IDictionary<Type, Type> _entityTransitions; public T Build<T>() => (T)Activator.CreateInstance(_entityTransitions[typeof(T)]);
As I understand the first one is more better because we have only casting, we don't need use reflection to build object. But I'm not sure, maybe it's incorrect. Which one should I use? Or maybe there is more better solution for this case? Thanks.
Aucun commentaire:
Enregistrer un commentaire