1

My scenario is the following:

I have an interface IVendor. I have three different classes implementing this, lets call them Vendor1, Vendor2, Vendor3.

I have a web api call that will give me availability of the vendor's products. Of course each vendor has its own check availability procedures, hence the interface that exposes a CheckAvailability method.

So in my call i have something like:

public bool Get(int productId)
{
    var product = GetProductByID(productId);
    switch(product.VendorId)
    {
        case 1:
            return Vendor1(CheckAvailability(product.VendorProductCode));
            break;
        case 2:
            return Vendor2(CheckAvailability(product.VendorProductCode));
            break;
        case 3:
            return Vendor3(CheckAvailability(product.VendorProductCode));
            break;
        default:
            return false;
            break;
    }
}

This is very simplistic and of course i do not like it. I would like to be able to call something like

public bool Get(int productId)
{
    var product = GetProductByID(productId);
    return IVendor.CheckAvailability(product.VendorProductCode)
}

and IVendor to be injected to whatever is needed through Ninject. Am i asking something crazy? Is that even possible?

Giannis Paraskevopoulos
  • 18,261
  • 1
  • 49
  • 69

0 Answers0