1 /* 2 * Copyright (C) 2020 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 app; 18 19 import dagger.Component; 20 import dagger.Module; 21 import dagger.Provides; 22 import javax.inject.Inject; 23 import javax.inject.Provider; 24 import javax.inject.Singleton; 25 26 /** A simple, skeletal application that defines a simple component. */ 27 public class SimpleComponentClasses { 28 static final class Foo { 29 @Inject Foo()30 Foo() {} 31 } 32 33 @Singleton 34 static final class ScopedFoo { 35 @Inject ScopedFoo()36 ScopedFoo() {} 37 } 38 39 static final class ProvidedFoo { ProvidedFoo()40 ProvidedFoo() {} 41 } 42 43 static final class ScopedProvidedFoo { ScopedProvidedFoo()44 ScopedProvidedFoo() {} 45 } 46 47 @Module 48 static final class SimpleModule { 49 @Provides provideFoo()50 static ProvidedFoo provideFoo() { 51 return new ProvidedFoo(); 52 } 53 54 @Provides 55 @Singleton provideScopedFoo()56 static ScopedProvidedFoo provideScopedFoo() { 57 return new ScopedProvidedFoo(); 58 } 59 } 60 61 @Singleton 62 @Component(modules = SimpleModule.class) 63 interface SimpleComponent { foo()64 Foo foo(); 65 scopedFoo()66 ScopedFoo scopedFoo(); 67 providedFoo()68 ProvidedFoo providedFoo(); 69 scopedProvidedFoo()70 ScopedProvidedFoo scopedProvidedFoo(); 71 scopedFooProvider()72 Provider<ScopedFoo> scopedFooProvider(); 73 scopedProvidedFooProvider()74 Provider<ScopedProvidedFoo> scopedProvidedFooProvider(); 75 } 76 } 77