dimanche 26 avril 2020

Autofac multiple implementation of same interface and implements are called in a if logic

I have an interface called ibaseinterface using which I have created 2 classes lets say baseclass1 and baseclass2.

Now I have a class named as top-level as below

public class toplevel
{
    public ibaseinterface selection(string selection)
    {
        int.TryParse(selection, out int sel);
        if (sel < 2)
            return new baseclass1();
        else
            return new baseclass2();
    }
}

based on user input I select the class that needs to be called. so how do I resolve the dependencies, in this case, using autofac.

Note: I definitely can't have different interfaces for the base classes.

Aucun commentaire:

Enregistrer un commentaire