Version
4.2.0
Steps to reproduce
In test hooks like @BeforeAll()
, re-register a dependency using the ioc
:
@BeforeAll()
public async beforeAll() {
ioc.instance('App/Services/AppService', {})
}
The above code doesn't change the appService
injected in the controller because the @Inject()
annotation is executed when appController
is imported to be registered in the service container.
Expected behavior
I expect to be able to re-register dependencies of any type and in an any time.
Actual behavior
Re-registering dependencies in runtime is not possible.
Additional context
This means that we need to refactor @Inject()
annotation to use a proxy like Facade
to respect when the service is not registered yet, and also to be able to re-register service providers in runtime.
This means that @Service()
annotation should also not really register the dependency, but only prepare it to be registered by CoreProvider
that will import all the services registered in the .athennarc.json
file.
Goal
None service provider could be "resolved" from the service container until the first user interaction with the application starts from the client.
In other words, Athenna cannot call use()
and safeUse()
methods when bootstrapping the application, only by closures.
Environment
System:
OS: macOS 13.5.2
CPU: (8) arm64 Apple M1 Pro
Memory: 77.44 MB / 16.00 GB
Shell: 5.9 - /opt/homebrew/bin/zsh
Binaries:
Node: 18.14.2 - ~/.nvm/versions/node/v18.14.2/bin/node
npm: 9.5.0 - ~/.nvm/versions/node/v18.14.2/bin/npm