question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

this object cannot be resolved directly

See original GitHub issue

Hi!

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:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wasinskicommented, Oct 25, 2021

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!

1reaction
proofit404commented, Oct 20, 2021

I had a glance to the crewmate project and it looks like your’s approach is to override Injectors class definitions I found it a bit overwhelming to be redefining so many Injectors (we had loads of fakes then).

Yes, you are correct, at that moment we kinda forced to use this expression to reference neighbor nested Injector.

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 🙏

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found