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.

Inconsistent base class injection behavior

See original GitHub issue

while migrating from 4.x to 6.4 I found that injecting base classes does not work as it used to and depending how injection occurs, it’s also inconsistent.

what is the preferred way to handle / resolve class hierarchy instances as outlined below for 6.x?

class KodeinSandbox {
    open class Resource1
    open class Resource2 : Resource1()

    val kodein = Kodein {
        bind<Resource1>() with singleton { Resource1() }
        bind<Resource2>() with singleton { Resource2() }
    }

    val instanceLevelResource1: Resource1 by kodein.instance()

    @Test
    fun testInjection() {
        val localResource1: Resource1 by kodein.instance()

        // Behaves as expected (as of 4.x) delivers instance explicitly bound to base-class type
        println(localResource1)

        // Throws due to ambiguity
        println(instanceLevelResource1)
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
masc3dcommented, Oct 7, 2019

confirming, 6.4.1 fixes this, as well as the overriding issue I presumed was related.

1reaction
romainbslcommented, Oct 7, 2019

6.4.1 fix the bug, I hope this will help. Tell me if you still have issues. (publishing on jcenter may take some minutes)

Read more comments on GitHub >

github_iconTop Results From Across the Web

base class is less accessible than child class - Stack Overflow
So this says that base class should be equally or more accessible than subclass. So if base class is internal then subclass should...
Read more >
Automocking and the Dependency Inversion Principle
This is how the error Inconsistent accessibility: base class 'WithSubject<HelloWorld>' is less accessible than class 'When_GetMessage' is solved ...
Read more >
how to restrict the access of members of a base class to ...
It would violate the principle of polymorphism[^]: A subclass should behave like the baseclass if it is being used like the baseclass.
Read more >
C#–Hide a base class for usage outside an assembly
I created an abstract base class in C# but didn't want it to be used outside the assembly I created it in. How...
Read more >
base class 'A' is less accessible than class 'B' - MSDN - Microsoft
public class B : A { } When I am trying to build the solution I am getting the following error: Error: Inconsistent...
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