How can I late load additional BinderModules

36 views
Skip to first unread message

Joshua Gerth

unread,
Jun 11, 2014, 5:03:36 PM6/11/14
to sil...@googlegroups.com
Hello,

So far using Silk-DI has been great, but I have one question I can't resolve from your documentation.  How can I late load additional BinderModules?

My application has the basics:

Main.java
             final Injector injector = Bootstrap.injector(RootBundle.class);
             
RootBundle.java
    @Override
    protected void bootstrap() {
        install(ProductionModule.class);
    }

which all works great.  Except I also have another Module that I may wish bind additional injectors later if the users' roles support it.  So ideally something where I could say

if (some_condition) {
      injector.add(MoreBundle.class);
}


Is this possible?  Has anyone done this?  Did I miss the documentation page which talked about this?

Thanks,
   Joshua

jan

unread,
Jun 12, 2014, 4:51:46 AM6/12/14
to sil...@googlegroups.com
Hello,

in general a injector container is bootstrapped once and stays as it is. This is important to have predictability of behaviour. Actually adding more to its context dynamically is not possible and should not be build. 
But.. think like this: You could always add the bundle with your role dependent behaviour and use types of bindings that support the dynamics you are trying to create for the user's role.
Configuration dependent bindings might be a thing for you http://www.silkdi.com/userguide/binds.html#config .
If this doesn't do as one alternative of a enum is not dynamic enough for you you might need to write your own Supplier or Scope depending on the concrete dynamics of your roles.

Cheers,
Jan
Reply all
Reply to author
Forward
0 new messages