-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Currently any read-through.loader and write-through.writer instances are created using FactoryBuilder.factoryOf("className") which just delegates to Class.forName("className").newInstance(). This is fine for simple loaders, but I find that I want to inject a dependency into my CacheLoader/Writers so that they can connect to some remote persistent storage.
It would be nice if the creation of these loaders could be handled by Guice, if so configured. Here's a quick stab at how it could be done: https://github.com/ben-manes/caffeine/compare/master...chrisstockton:guice-factory?expand=1
It relies on static injection of an injector which doesn't seem super ideal, but considering the alternative is just using Class.forName(...).newInstance(), it at least doesn't seem like a step back.
It would also require someone to make a call to requestStaticInjection(GuiceFactory.class) in a module somewhere, but that seems not too onerous.