guice
Dependency Injection by Google for Java
Before DI
Need to wire everything together
This relies on actual implementations of creditcardprocesser making testing difficult as well as switching implementations
Factories?
Now can do proper tests, but need to setup and teardown and dependencies setup as needed per inner functionfunction extractMessagesFromJade(filePath, baseDirectory, callback) { fs.readFile(filePath, (err, content) => { if (err) { callback(err); } else { let messages = []; const jadeOptions = { compiler: yudi, filename: filePath, basedir: baseDirectory, attrs: JADE_ATTRS, postCompile: (compiler) => { messages = compiler.strings; }, }; try { jade.compileClient(content, jadeOptions); } catch (e) { callback(e); } callback(null, { messages: cleanMessages(messages), }); } }); }
DI
Put in constructor of object
Guice
Map interfaces to implementations in Module
add @Inject
to constructor and directs Guice to use it by looking up values for each parameter
Last updated