1 /* 2 * Copyright (C) 2021 The Dagger Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dagger.hilt.android.simple; 18 19 import android.app.Application; 20 import dagger.hilt.EntryPoint; 21 import dagger.hilt.EntryPoints; 22 import dagger.hilt.InstallIn; 23 import dagger.hilt.android.EarlyEntryPoint; 24 import dagger.hilt.android.EarlyEntryPoints; 25 import dagger.hilt.components.SingletonComponent; 26 import javax.inject.Inject; 27 import javax.inject.Singleton; 28 29 /** A custom application used to test @EarlyEntryPoint */ 30 public class BaseTestApplication extends Application { 31 @EarlyEntryPoint 32 @InstallIn(SingletonComponent.class) 33 interface EarlyFooEntryPoint { earlyFoo()34 Foo earlyFoo(); 35 } 36 37 @EntryPoint 38 @InstallIn(SingletonComponent.class) 39 interface FooEntryPoint { lazyFoo()40 Foo lazyFoo(); 41 } 42 43 @Singleton 44 public static final class Foo { 45 @Inject Foo()46 Foo() {} 47 } 48 49 private Foo earlyFoo; 50 51 @Override onCreate()52 public void onCreate() { 53 super.onCreate(); 54 earlyFoo = EarlyEntryPoints.get(this, EarlyFooEntryPoint.class).earlyFoo(); 55 } 56 earlyFoo()57 public Foo earlyFoo() { 58 return earlyFoo; 59 } 60 lazyEarlyFoo()61 public Foo lazyEarlyFoo() { 62 return EarlyEntryPoints.get(this, EarlyFooEntryPoint.class).earlyFoo(); 63 } 64 lazyFoo()65 public Foo lazyFoo() { 66 return EntryPoints.get(this, FooEntryPoint.class).lazyFoo(); 67 } 68 } 69