I’ve got dry-system wired up, and it appears that by default auto-registered objects injected by
Import are created by calling
new on the class name, with no arguments. However, that is not always what I want.
There are two cases, in particular, that I have questions about.
- The constructor of the injected class requires one or more arguments, and the arguments should be provided by the class into which it’s being injected. How is this case supposed to be handled? If we imagine a constructor with 2 arguments, the first of which is specified at runtime and contains the argument we need to pass to the constructor of the 2nd argument, then what we want is for the class itself to be injected as the 2nd argument, and then we would be able to
newthat class with the information from the first argument. There may be other solutions too…
- I am injecting a module of pure static functions. That is, I want the module itself to be injected – I don’t want to call
Both of these cases would be simple enough to solve if I were configuring the container by hand user
register. But what is the correct way to solve them while also using auto-register?