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

Better module api #1

Merged
merged 7 commits into from Feb 27, 2018
Merged

Better module api #1

merged 7 commits into from Feb 27, 2018

Conversation

JLLeitschuh
Copy link
Owner

The changes to the README sum up the changes pretty well.

Guice Modules

Creating a module in Java requires quite a bit of extra boilerplate.

public class MyModule extends AbstractModule {
    @Override
    void configure() {
        bind(SomeService.class).to(SomeServiceImpl.class);
    }
}

class Main {
    public static void main(String... args) {
        final Injector injector = Guice.createInjector(new MyModule());
    }
}

This is the equivalent in Kotlin:

fun main(vararg args: String) {
    val myModule = module {
        bind(SomeService::class).to(SomeServiceImpl::class)
    }
    val injector = Guice.createInjector(myModule)
}

@SamCarlberg you want to take a look at this PR?

* is called by Guice.
*/
fun module(configure: BinderScope.() -> Unit) =
Module { binder -> BinderScope(binder).configure() }
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the big addition here that actually makes the API in the readme possible.

}
}

// Below, configure jacoco code coverage on all Junit 5 tests.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, all of these Jacoco changes probably should have been in a different PR. But whatever.

* See the EDSL examples at [com.google.inject.Binder].
*/
fun to(implementation: KClass<out T>): ScopedBindingBuilderScope =
ScopedBindingBuilderScope(to(implementation.java))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ This is now double decorated. I should fix this.

@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, and I probably shouldn't have updated the version of gradle as a part of this PR either.

/**
* See the EDSL examples at [com.google.inject.Binder].
*/
override fun annotatedWith(annotationType: Class<out Annotation>): LinkedBindingBuilder<T> =
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ This should be returning LinkedBindingBuilderScope.

/**
* See the EDSL examples at [com.google.inject.Binder].
*/
fun annotatedWith(annotationType: KClass<out Annotation>): LinkedBindingBuilder<T> =
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ This should be returning LinkedBindingBuilderScope.

/**
* See the EDSL examples at [com.google.inject.Binder].
*/
override fun annotatedWith(annotation: Annotation): LinkedBindingBuilder<T> =
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ This should be returning LinkedBindingBuilderScope.

@JLLeitschuh JLLeitschuh merged commit 7b88a15 into master Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant