This related question shows examples from the documentation but doesn't explain practical difference between InversifyJS toFactory
and toDynamicValue
toDynamicValue
accepts factory function while toFactory
accepts higher-order factory function. But toDynamicValue
could return factory function as a value, too.
Can they serve same purpose and how can their behaviour be different?
How do Bar
and Baz
differ in this example?
container.bind('Bar').toDynamicValue(
context => fooName => context.container.getNamed(Foo, fooName)
)
container.bind('Baz').toFactory(
context => fooName => context.container.getNamed(Foo, fooName)
)