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

Pommel should provide a way to generate a module for a field #11

Open
KVelasco opened this issue Aug 6, 2020 · 0 comments
Open

Pommel should provide a way to generate a module for a field #11

KVelasco opened this issue Aug 6, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@KVelasco
Copy link
Contributor

KVelasco commented Aug 6, 2020

Currently pommel only works on classes that have a constructor annotated with @Inject. This works if you own the class and mark the constructor with @Inject but there are cases where you don't own the class and want to provide an instance of said class in your dagger graph.

Let's say I'm building an Android application that connects to a REST API and I want to have the base url for my service on the dagger graph. You would normally do something like this

@Module
object ServiceModule {
    @Provides 
    @Named("baseUrl")
    fun providesBaseUrl(): String = "https:://api.service.com"

    ...  // more service module configuration 
}

If I wanted to replace baseUrl in testing I would have to create a module with just the baseUrl binding. Pommel should provide a way to annotate a field to generate the module for these types of bindings. Maybe something like the following

@SoloModule
@Named("baseUrl")
val baseUrl: String = "https:://api.service.com"

would generate the equivalent of:

public abstract class BaseUrl_SoloModule {
    @Provides 
    @Named("baseUrl") 
    public static String provides_baseUrl() {
        return "https:://api.service.com";
    }
}

We can perhaps repurpose the @SoloModule annotation to work on both a class and a field or possibly create a new annotation that works only on fields, Maybe @SoloField?

@KVelasco KVelasco added the enhancement New feature or request label Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant