Giter VIP home page Giter VIP logo

hilt-binder's People

Contributors

mars885 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hilt-binder's Issues

Crash when installing a binding in a custom component

For example:

// A custom component's scope annotation
@Scope
@Retention(value = AnnotationRetention.RUNTIME)
annotation class CustomScope

// Declaration of a custom component itself
@CustomScope
@DefineComponent(parent = SingletonComponent::class)
interface CustomComponent

interface ImageLoader
interface Logger

@CustomScope
@BindType
class PicassoImageLoader @Inject constructor(): ImageLoader

@BindType(
 installIn = BindType.Component.CUSTOM,
 customComponent = CustomComponent::class
)
class AndroidLogger @Inject constructor(): Logger

If the CustomScope annotation is declared in different package than the CustomComponent interface, the following error is thrown when building the project: Collection contains no element matching the predicate..

The above bug entails that having only custom scope annotation present on the binding type is not enough, since it's impossible to infer a class of the custom component from the scope annotation itself. This means that the installIn and the customComponent parameters should be set regardless if the type is scoped or unscoped. For example:

// A custom component's scope annotation
@Scope
@Retention(value = AnnotationRetention.RUNTIME)
annotation class CustomScope

// Declaration of a custom component itself
@CustomScope
@DefineComponent(parent = SingletonComponent::class)
interface CustomComponent

interface ImageLoader
interface Logger

// Binding unscoped type
@BindType(
 installIn = BindType.Component.CUSTOM,
 customComponent = CustomComponent::class
)
class PicassoImageLoader @Inject constructor(): ImageLoader

// Binding scoped type
@CustomScope
@BindType(
 installIn = BindType.Component.CUSTOM,
 customComponent = CustomComponent::class
)
class AndroidLogger @Inject constructor(): Logger

// Won't work, can't infer CustomComponent from CustomScope
// @CustomScope
// @BindType
// class AndroidLogger @Inject constructor(): Logger

Migration away from JCenter

Since Bintray is going away, are you planning to migrate to library to Maven Central or JitPack?

Great job btw, it is baffling to me why the Hilt does not have to built in

InstallIn custom component

For now, installIn requires usage of Component enum. I have to install my class in custom component. Can i do that right now? If not - i think it's crucial to have this. In my case - i'm trying to get rid of boilerplate when using Maverics with Hilt. I have such component:

@MavericksViewModelScoped
@DefineComponent(parent = SingletonComponent::class)
interface MavericksViewModelComponent

Allow specifying both scope annotation and explicit predefined component

The latest version, 1.0.0-alpha02, does not allow to do the following:

interface ImageLoader

@ActivityScoped
@BindType(installIn = BindType.Component.ACTIVITY)
class PicassoImageLoader @Inject constructor(): ImageLoader

When building the aforementioned snippet, the compiler throws the following error:

error: @BindType-using type specifies the component both by the scope annotation and in the 'installIn' parameter of the annotation.

The aforementioned requirement will be dropped, since there is nothing wrong when specyfing both the scope annotation and explicit predefined component as long as they match (e.g., ActivityScoped and BindType.Component.ACTIVITY, ServiceScoped and BindType.Component.SERVICE, and so on). In case they don't, an error will be raised by the compiler.

Docs: Binding multiple types to the same interface

It would be nice to have documentation in the readme about what happens when you bind two types to the same interface without the multibinding annotation (@BindType(contributesTo = BindType.Collection.SET)) and without qualifiers:

interface ImageLoader

@BindType
class PicassoImageLoader @Inject constructor(): ImageLoader

@BindType
class GlideImageLoader @Inject constructor(): ImageLoader

It's been a while since I've used dagger, but I would expect that not to work since the instance resolution becomes ambiguous.

Support for Kotlin 1.9.0

After updating Kotlin from "1.8.22" to "1.9.0" and
KSP "1.8.22-1.0.11" to "1.9.0-1.0.11" all bindings failing

Error Hilt is giving is you need to annotate with @provides or @BINDS

Generate wildcards for generic type

I want to create multibinding for such collection:

interface HiltMavericksEntryPoint {
    val viewModelFactories: Map<Class<out MavericksViewModel<*>>, AssistedViewModelFactory<*, *>>
}

I'm trying to use hilt binder like that:

@BindType(
        to = AssistedViewModelFactory::class,
        contributesTo = BindType.Collection.MAP
    )
    @ViewModelKey(DashboardViewModel::class)
    @AssistedFactory
    interface Factory : AssistedViewModelFactory<DashboardViewModel, DashboardState> {
        override fun create(state: DashboardState): DashboardViewModel
    }

this generated code like that:

@Module
@InstallIn(SingletonComponent.class)
public interface TestModule {
    @Binds
    @IntoMap
    @ViewModelKey(DashboardViewModel.class)
    AssistedViewModelFactory bind(
            DashboardViewModel.Factory binding);
}

but dagger won't accept that as a member of Map<Class<out MavericksViewModel<*>>, AssistedViewModelFactory<*, *>>. I tested very similar module and it's working fine:

@Module
@InstallIn(SingletonComponent.class)
public interface TestModule {
    @Binds
    @IntoMap
    @ViewModelKey(DashboardViewModel.class)
    AssistedViewModelFactory<?, ?> bind(
            DashboardViewModel.Factory binding);
}

The only thing i added are the wildcards for the generic type, and now it's working great.

I even tried to workaround this by using @JvmSuppressWildcards, but does not seem to help. Even this weird construct is failing:

@JvmSuppressWildcards
    val viewModelFactories: @JvmSuppressWildcards Map<@JvmSuppressWildcards Class<out @JvmSuppressWildcards MavericksViewModel<*>>, @JvmSuppressWildcards AssistedViewModelFactory<*, *>>

Is is possible to use hilt-binder multibinding with generic types?

@BindType as a repeatable annotation in Kotlin 1.6.0

If i understand correctly - kotlin 1.6.0 is lifting the restriction on the @Repeatable, so it can be used on any retention. I think multiple binds would be a great addition to this otherwise underestimated library

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.