Creating a new injector, with new bindings, but keep all singletons?

2014-10-18 Thread Kevin Burton
Long story short, I've painted myself into a corner. I was creating new modules and a new injector in some code each time a service started. The problem is I need to keep state by moving over singletons to the new injector. The problem is, some of these bindings are now changes and possibly r

Re: Creating a new injector, with new bindings, but keep all singletons?

2014-10-19 Thread Nate Bauernfeind
It sounds like you might want to use a childInjector pattern here. Structure it something like this: Global Injector binds everything that is truly a singleton in your project. Then in the service(s) where you want to be able to set some state and create a new object that references the global sta

Re: Creating a new injector, with new bindings, but keep all singletons?

2014-10-19 Thread Kevin Burton
This is my understanding as well... However, my problem is that if I update the bindings , say by replacing one with a new binding, then when I create the child injector it fails because that binding was "already configured" I replace bindings because during init various systems changes. For

Re: Creating a new injector, with new bindings, but keep all singletons?

2014-10-19 Thread Nate Bauernfeind
I don't really understand how you aren't able to come up with a static set of singletons that you want to be changing at each type of request. The solution that you're trying to take sounds like a terribly hard one to maintain. I advise you to look, seriously, into picking an alternative dependenc

Re: Creating a new injector, with new bindings, but keep all singletons?

2014-10-19 Thread Kevin Burton
I'm aware that it's probably that I might need to refactor some things ... However, I'm not sure the ideal way to have certain bindings, without replacing them. I have one binding, Caller, which is literally just a string explaining what root service called an object. This way I can trace thi

Re: Creating a new injector, with new bindings, but keep all singletons?

2014-10-19 Thread Nate Bauernfeind
Do you ever run two tasks simultaneously? If not, perhaps you can create a special provider that you can swap out the Caller where you're currently considering creating a new injector. import com.google.inject.Provider; import java.util.concurrent.atomic.AtomicReference; public class CallerProvid

Re: Creating a new injector, with new bindings, but keep all singletons?

2014-10-19 Thread Stephan Classen
You can also use custom scopes to change the returned instance depending on your logic. This may be a little cleaner than having too much logic in the providers. On 10/19/2014 06:55 PM, Nate Bauernfeind wrote: Do you ever run two tasks simultaneously? If not, perhaps you can create a special p