this object cannot be resolved directly
See original GitHub issueHi!
I’m having a bit of a problem with DependencyError: 'this' dependencies could only be used to instantiate classes
error.
It’s limiting me in in case of scopes, especially applying Decorator Pattern:
class UsersModuleCommands(Injector):
create_user_handler = this.LoggingCreateUserCommandHandler.handler.
class LoggingCreateUserCommandHandler(Injector):
handler = LoggingCommandHandlerDecorator
decoree = this.Handler.handler
logger = (this << 1).logger
class Handler(Injector):
handler = CreateUserHandler
transaction = (this << 2).transaction
user_repository = (this << 2).user_repository
# transaction and logger are provided from outer-scope
I solved that by creating a “proxy class” that is constructed by Injector and is wrapping the decorated handler, but that’s hacky.
A similar problem arose when I needed to create a scope due to argument names not being unique, something like:
class Deps(Injector):
service = this.ScopedDeps.service
class ScopedDeps(Injector):
service = A
arg = (this << 1).config["arg"]
# config provided from outer-scope
Am I doing something wrong? 😉
PS: Thanks for all your hard work!
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Java project in Eclipse: The type java.lang.Object cannot be ...
I was facing this issue with play-java application on eclipse after adding a controller, I removed and reinstalled JRE through build path and ......
Read more >"The type java.lang.Object cannot be resolved" when building ...
Object cannot be resolved " when building multithreaded with OpenJDK17 #1099 ... Then it might not be directly related but toolchains are ...
Read more >Java project in Eclipse: The type java.lang.Object ... - Intellipaat
I am getting the following error after importing a project in Eclipse: The type java.lang. ... through Window Preferences Java Installed ...
Read more >The type java.lang.Object cannot be resolved. It is indirectly ...
1 Answer · Close the project and reopen it. · Clean the project (It will rebuild the build path hence reconfiguring with the...
Read more >'The type Java.lang.Object cannot be resolved. It is indirectly ...
Question: How can the following error be resolved for a Java application in Eclipse: "The type Java.lang.Object cannot be resolved.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s very kind! Thank you. I will need to implement something like “dynamic dependency injection” - creating of EventHandlers that share the same “infrastructure” dependencies (like transaction), and I expect that to be a little bit of a challenge, but for now, I will try to solve it on my own - I have some ideas around either using Sticky Scopes, or resolving it by using some custom wrappers around Injector that would hold such scoped dependencies. Thanks again though!
Yes, you are correct, at that moment we kinda forced to use
this
expression to reference neighbor nestedInjector
.I can’t say how this approach annoys me. I hope I would came with something better in the future. And it won’t be yet another service locator implementation 😄
If you have any ideas what alternative solution could be, please file an issue 🙏