0

I was wondering if it is possible to pass a different class based on the query you're currently on in DI in HotChocolate.

So saying I have an interface like :

     public interface IPrinter
        {
            public string Print();
        }

and classes that implement the interface :

   public class PhysicalPrinter : IPrinter{
    public string Print(){
    //do some stuff
    }


public class Digitalprinter : IPrinter{
        public string Print()
        {
            // do other stuff
        }
    }

And I have the following queries :

enter image description here

Is there any way I can tell HotChocolate to use the PhysicalPrinter when it's inside "Customer" and when the query is "administration" it will use the DigitalPrinter ?

Makus
  • 99
  • 1
  • 8

1 Answers1

1

Maybe using enums will be solve your problem.

public enum UserType
{
    AdminType,
    CustomerType
}

public void Print(UserType userType) 
{
    IPrinter printer;
    switch(userType)
    {
        //write your logic
    }
}       
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Onur Bilen
  • 11
  • 1