Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generating definitions for object declarations #72

Closed
ithersta opened this issue Feb 8, 2023 · 10 comments
Closed

Support generating definitions for object declarations #72

ithersta opened this issue Feb 8, 2023 · 10 comments
Labels
question Further information is requested status:duplicate This issue or pull request already exists status:wontfix This will not be worked on

Comments

@ithersta
Copy link

ithersta commented Feb 8, 2023

Is your feature request related to a problem? Please describe.
I use JetBrains Exposed and I have several tables declared like so:

object Users : LongIdTable() {
    val name: Column<String> = varchar("name", length = 256)
    ...
}

I want to annotate all tables with @Single and then use getAll<Table>():

SchemaUtils.createMissingTablesAndColumns(*getAll<Table>().toTypedArray())

But the generated definitions for objects call a non-existent constructor and the project doesn't compile.

single(qualifier=null) { auth.data.tables.Users() }

Describe the solution you'd like
Generate a proper definition for object declaration without calling a constructor.

Describe alternatives you've considered
I tried turning object into a class but it's not ideal since the object is used a lot in queries like so:

Users.batchInsert(user.areas) {
    this[Users.name] = user.name
    ...
}

Target Koin project
koin-annotations

@ninja-
Copy link

ninja- commented Feb 12, 2023

object compiles to an internal class without public constructor and one JVM-global INSTANCE field with the instance.
It really doesn't sound like a good match for a DI system like Koin.

I don't know exposed that well, but you probably should turn the object back into class, and only reference it using injected instance, even if it may queries a bit more annoying.

Alternatively, try binding a factory where Users is the type and returned data is Users itself - the object.

@arnaudgiuliani arnaudgiuliani added the question Further information is requested label Mar 23, 2023
@arnaudgiuliani
Copy link
Member

yep, not sure to see the real case. Also Ktor is generating content, not sure about compatibility with Koin Annotations here 🤔

@ithersta
Copy link
Author

Well, my use case is to automatically find all the tables in my code (and canonically they are objects in Exposed) so I don't have to list them manually during schema creation. It's not really about dependency injection, more like plugin discovery, so maybe it's out of scope for Koin.

@ithersta
Copy link
Author

I can submit a PR if you want to

@undermark5
Copy link

A work around is to declare operator fun invoke() = this on the objects. It may not be pretty, but it is a valid work around (koin really should only call the constructor if the definition isn't an object (which is known during KSP), I ran into the same issue with defining a module as an object and the invoke operator function did the trick)

Copy link

stale bot commented Mar 30, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status:wontfix This will not be worked on label Mar 30, 2024
@undermark5
Copy link

This seems like something similar to #107 would work here.

@stale stale bot removed the status:wontfix This will not be worked on label Mar 30, 2024
@arnaudgiuliani
Copy link
Member

yes duplicated

@arnaudgiuliani arnaudgiuliani added the status:duplicate This issue or pull request already exists label Apr 4, 2024
@undermark5
Copy link

Not exactly. Last I checked #107 only impacted module definitions, not dependency definitions. That is that I don't think that #107 in it's current form provides a solution for this issue.

Copy link

stale bot commented Sep 1, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status:wontfix This will not be worked on label Sep 1, 2024
@stale stale bot closed this as completed Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested status:duplicate This issue or pull request already exists status:wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants