Dagger does not support providing @AssistedInject types
See original GitHub issueI am using Hilt (v2.32-alpha) dependency injection with viewmodel. I have a class with 2 parameters, the first is context and the second is an optional string so if not provide any value this takes null. To achieve this in Hilt I read below doc: https://dagger.dev/dev-guide/assisted-injection.html
This is my code :
class SharedPreferencesHelper @AssistedInject constructor(
context: Context,
@Assisted sharedPreferencesName: String? = null
) { ... }
And Hilt Module :
@Module
@InstallIn(ViewModelComponent::class)
object WebServicesModule {
@Provides
fun provideSharedPreferencesHelper(@ApplicationContext context: Context): SharedPreferencesHelper =
SharedPreferencesHelper(context)
}
AssistedFactory interface:
@AssistedFactory
interface MyAssistedFactory {
fun create(sharedPreferencesName: String): SharedPreferencesHelper
}
And my viewmodel :
@HiltViewModel
class SplashViewModel @Inject constructor(
application: Application,
savedStateHandle: SavedStateHandle,
private val repository: SplashRepository
) : AndroidViewModel(application) {
@Inject
lateinit var assistedFactory: MyAssistedFactory
fun callSplashApi() {
val preferencesHelper = assistedFactory.create("ss")
...
}
}
But build fails with this error:
Dagger does not support providing @AssistedInject types.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Inject WorkManager with Hilt but getting error "Dagger does ...
The error states that you are trying to @Provides a class with an @AssistedInject constructor. This makes sense: after all, there is no...
Read more >Assisted Injection - Dagger
@AssistedInject types cannot be injected directly, only the @AssistedFactory type can be injected. This is true even if the constructor does not contain...
Read more >Inject WorkManager with Hilt but getting error "Dagger does ...
Coding example for the question Inject WorkManager with Hilt but getting error "Dagger does not support providing @AssistedInject types."-kotlin.
Read more >Inject Workmanager With Hilt But Getting Error ... - ADocLib
... But Getting Error "Dagger Does Not Support Providing @Assistedinject Types." ... Home Dagger Hilt Dagger Tutorial These are some of the questions...
Read more >Brave New Android World with AssistedInject - ProAndroidDev
'Hey Dagger! Please provide me following component with Dependency1, Dependency2, … and DependencyX BUT be kind and let me provide DependencyX on my...
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
@alizarei95, note that #2370 will allow you to provide a qualified
@AssistedInject
type, but we’re still not allowing an unqualified@AssistedInject
type to be provided to avoid confusion.Thus, you’ll have to provide your default type with a qualifier like,
@Default
.You probably also want to provide the default via the factory rather than calling the constructor directly. For example:
**Also, note that the fix for #2370 is not yet included in a release. It should be out with the next Dagger release, 2.33.
Closing this as a dupe of #2370