Decorators, nested Implementations sharing the same interface

24 views
Skip to first unread message

Mats Svefors

unread,
Jul 4, 2013, 12:24:40 PM7/4/13
to sil...@googlegroups.com
Hello,

How does one go about injecting Decorators? 

Is it possible to do the following:

interface PlaceController {
     void goto()
}

class PlaceControllerImpl implements PlaceController {
...
}

class SecurePlaceController implements PlaceController {
     PlaceController inner;
     public SecurePlaceController(PlaceController b){
         this. inner = b;
     }
     void goto(){
       if(x)
         inner.goto()
       else
         foo()
     }
}

class ConsumerCodeSomewhere {
    PlaceController somePlaceController;
}

So i want the ConsumerCodeSomewhere to be injected with the SecurePlaceController that in turn is injected with whatever implementation of PlaceController was defined. My design goal would be to not have the SecureModule know which class is implementing the PlaceController interface.

Regards,
Mats

jan

unread,
Jul 4, 2013, 3:54:17 PM7/4/13
to sil...@googlegroups.com
Hi Mats,

this is a basic case in Silk. You can target the binds as described here http://www.silkdi.com/userguide/binds.html#targeting

protected void declare() {
  injectingInto( ConsumerCodeSomewhere.class ).bind( PlaceController.class ).toSecurePlaceController.class );
  injectingInto( 
SecurePlaceController.class ).bind( PlaceController.class ).to( PlaceControllerImpl.class );
}

This can - of cause - appear in different modules if you like.

/Jan
Reply all
Reply to author
Forward
0 new messages