mardi 6 juillet 2021

C# using reflections vs saving Dictionary of References [closed]

I'm making web application, using clean architecture

public class UnitOfWork : IUnitOfWork
{
        private PMToolContext Context;

        public UnitOfWork(PMToolContext context)
        {
              Programs = new NamedRepository<Program>(context);
              Analogues = new NamedRepository<Analogue>(context);
              Interfaces = new NamedRepository<Interface>(context);
              Technologies = new NamedRepository<Technology>(context);
              Teams = new NamedRepository<Team>(context);
        }

        public INamedModelRepository<Program> Programs { get; private set; }

        public INamedModelRepository<Analogue> Analogues { get; private set; }

        public INamedModelRepository<Interface> Interfaces { get; private set; }

        public INamedModelRepository<Technology> Technologies { get; private set; }

        public INamedModelRepository<Team> Teams { get; private set; }
}

I want to get repository by it's name (string). I have two ideas on how to do this either I could use reflections or I could create a Dictionary that saves the references to those repositories, using strings as keys. Which of these methods is the "correct" one? From the point of readability, security and performance





Aucun commentaire:

Enregistrer un commentaire