lundi 25 avril 2016

Unity register types using Reflection

I'm trying to do the following:

foreach (var item in Assembly.GetExecutingAssembly()
                             .GetTypes()
                             .Where(i => i.GetInterfaces()
                             .Contains(typeof(ITabItem))))
{
    container.RegisterType<ITabItem, item>(nameof(item));
}

But I'm getting this error on item in the RegisterType method:

Error CS0118 'item' is a variable but is used like a type

I know that I'm passing an object type but how do I get around this?

EDIT: this is the non-dynamic way that works.

container.RegisterType<ITabItem, AdminViewModel>(nameof(AdminViewModel));
container.RegisterType<ITabItem, OwnerViewModel>(nameof(OwnerViewModel));





Aucun commentaire:

Enregistrer un commentaire