mardi 13 novembre 2018

Dependency injection by type names

For my example I use Autofac (it's not necessary):

var r = builder.RegisterType<Helper>().As<IHelper>(); // usual using

What I'd like to do is to be able to register types somehow like:

string name1 = "Helper";

string name2 = "IHelper";

var r = builder.RegisterType<GetTypeFromName(name1)>().As<GetTypeFromName(name2)>();

Is it possible to do with reflection magic?





Aucun commentaire:

Enregistrer un commentaire