Simple Injector decorator for non-generic interface -


i tried following doesn't work (activationexception).

public interface iop { object execute(object value); }  public class simpleop : iop { public object execute(object value) { return value; } }  public class compressop : iop {     private readonly iop nextop;     public compressop(iop nextop) { this.nextop = nextop; }     public object execute(object value)     {         return this.compress(this.nextop.execute(value));     } }  var container = new container(); container.registerall<iop>(typeof(simpleop), typeof(compressop)); container.registerdecorator(typeof(iop), typeof(compressop)); var op = container.getinstance<iop>(); <-- activationexception 

the iop interface doesn't need generic type because it's designed same processing object. have force generic use object type parameter, can use decorator pattern?

try this

var container = new container(); container.register<iop, simpleop>(); container.registerdecorator(typeof(iop), typeof(compressop)); var op = container.getinstance<iop>(); 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -