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

Is nesting @Assisted possible? #407

Open
ursusursus opened this issue Jun 22, 2024 · 1 comment
Open

Is nesting @Assisted possible? #407

ursusursus opened this issue Jun 22, 2024 · 1 comment
Labels
question Further information is requested

Comments

@ursusursus
Copy link

ursusursus commented Jun 22, 2024

Hi, I'm migrating from dagger and noticed this library supports assisted injection natively, so I'm triying it out (I didn't use it in dagger because of the extra dependency).

At UI layer I have conductor Controller (Fragment equivalent), which has all the lifecycle callbacks & functions + it implements navigation for me

class ChatViewModel(
    private val dispatcherProvider: DispatcherProvider,
    private val intentHelper: IntentHelper,
    private val navigator: ChatNavigator
)

class ChatController : conductor.Controller, ChatNavigator

interface ChatNavigator {
    fun goToFoo()
}

class IntentHelper(private val controller: Controller)

My current solution for this is to have a manual Factory

class ChatViewModelFactory @Inject constructor(
    private val dispatcherProvider: DispatcherProvider,
) {
    fun create(controller: ChatController) {
        return ChatViewModel(
            dispatcherProvider = dispatcherProvider,
            intentHelper = IntentHelper(controller),
            navigator = controller
        )
    }
}

Is this something I can do away with using @Assisted?
Simple example obviously works

@Inject
class ChatViewModel(
    private val dispatcherProvider: DispatcherProvider,
    @Assisted private val navigator: ChatNavigator
)

But adding the IntentHelper causes me trouble

@Inject
class ChatViewModel(
    private val dispatcherProvider: DispatcherProvider,
    private val intentHelper: IntentHelper, <------------
    @Assisted private val navigator: ChatNavigator
)

@Inject
class IntentHelper(@Assisted private val controller: Controller) <------

I'm trying to have it be part of the graph & have the controller asgument be assisted, but that then obviously requires the view model to depend on the factory private val intentHelper: (Controller) -> IntentHelper,, not the type itself

So .. is this even possible, or am I stuck with manual factories? (to not have Controller dependency explicitly in viewmodel constructor signature)

@evant
Copy link
Owner

evant commented Jun 23, 2024

I'm not sure I'm following your question, how would you expect to pass the controller arg?

@evant evant added the question Further information is requested label Jun 24, 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
Projects
None yet
Development

No branches or pull requests

2 participants