InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
9.12k stars 721 forks source link

inject doesn't work in Java in version 2.0.1 #631

Closed baruchn closed 5 years ago

baruchn commented 5 years ago

Describe the bug The following code:

import android.content.Context;
import android.util.Log;

import kotlin.Lazy;

import static org.koin.java.KoinJavaComponent.*;

class DITest {

    private static final String TAG = DITest.class.getSimpleName();

    private Lazy<Context> context = inject(Context.class);

    void test() {
        Log.d(TAG, "test: get context is " +get(Context.class));
        Log.d(TAG, "test: injected context is " +context);
    }
}

Results in:

test: get context is android.app.Application@c56973c test: injected context is Lazy value not initialized yet.

Using koin-java version 2.0.1.

baruchn commented 5 years ago

Sorry, was missing getValue() call.