Engine // use ) { fun start() { engine.start() } } fun main(args: Array) { val engine = Engine() // construct val car = Car(engine) car.start() } Car Engine
engine: Engine // use fun start() { engine.start() } } fun main(args: Array) { val car = Car() car.engine = Engine() // construct car.start() } Car Engine
Engine = Engine() } // Dependency Injection (Constructor Injection) class Car @Inject constructor( // use private val engine: Engine, ) Link: h tt ps://dagger.dev/hilt/quick-sta r @Injectܳ ਊೞৈ, ઓࢿਸ ېझ ࢤࢿী ੑೡ ࣻ . Car Engine
Engine = Engine() } // Dependency Injection (Constructor Injection) class Car @Inject constructor( // use private val engine: Engine, ) @AndroidEntryPoint class ExampleActivity : ComponentActivity() { // Dependency Injection (Field Injection) @Inject // use lateinit var car: Car } Link: h tt ps://dagger.dev/hilt/quick-sta r Android ېझח ࢤࢿо ইצ, ٘ী ઓࢿਸ ੑೠ. Car ExampleActivity Engine
bar: Bar } @AndroidEntryPoint class ExampleActivity : ComponentActivity() { @Inject lateinit var bar: Bar } @Module @InstallIn(SingletonComponent::class) internal object FooModule { @Provides fun provideBar(): Bar = Bar() } Link: h tt ps://dagger.dev/hilt/quick-sta r ExampleApplication_HiltComponents.java -> Hilt_ExampleApplication.java ExampleApplication_GeneratedInjector.java ExampleApplication_MembersInjector.java -> Hilt_ExampleActivity.java ExampleActivity_GeneratedInjector.java ExampleActivity_MembersInjector.java -> HiltWrapper_FooModule.java FooModule_ProvideBarFactory.java ӏ ࠁաਃ?
Hilt public final class ExampleApplication_HiltComponents { @Component(modules = { ActivityRetainedCBuilderModule.class, ... }) @Singleton public abstract static class SingletonC implements SingletonComponent { } ... } // -------------------------------------------------------------------------------- // Generated by Dagger public final class DaggerExampleApplication_HiltComponents_SingletonC { private static final class SingletonCImpl extends ExampleApplication_HiltComponents.SingletonC { public void injectExampleApplication(ExampleApplication exampleApplication) {} } ... } @HiltAndroidApp জ ઓࢿ Ӓېܳ ࢤࢿೞח ӝળ ػ.
return new Builder(); } public static final class Builder { public ExampleApplication_HiltComponents.SingletonC build() { return new SingletonCImpl(); } } private static final class SingletonCImpl extends SingletonC { private final SingletonCImpl singletonCImpl = this; private SingletonCImpl() { } } } п Component݃ ۠ ېझо ࢤࢿػ.
} // -------------------------------------------------------------------------------- public final class ExampleApplication_HiltComponents { @Component(modules = { ... }) @Singleton public abstract static class SingletonC implements HiltWrapper_ActivityRetainedComponentManager_ActivityRetainedComponentBuilderEntryPoint, SingletonComponent, GeneratedComponent, ExampleApplication_GeneratedInjector { } } // -------------------------------------------------------------------------------- public final class DaggerExampleApplication_HiltComponents_SingletonC { private static final class SingletonCImpl extends SingletonC { public void injectExampleApplication(ExampleApplication instance) { } }
bar: Bar } // -------------------------------------------------------------------------------- public final class ExampleApplication_MembersInjector implements MembersInjector<ExampleApplication> { public static void injectBar(ExampleApplication instance, Bar bar) { instance.bar = bar; } } // -------------------------------------------------------------------------------- public final class DaggerExampleApplication_HiltComponents_SingletonC { private static final class SingletonCImpl extends SingletonC { public void injectExampleApplication(ExampleApplication instance) { ExampleApplication_MembersInjector.injectBar( instance, FooModule_ProvideBarFactory.provideBar()); } } ࢤࢿػ Injector ېझח Componentী ୶оػ.
void injectExampleActivity(ExampleActivity instance) { ExampleActivity_MembersInjector.injectBar(instance, new Bar()); } } @AndroidEntryPoint class ExampleActivity : ComponentActivity() { @Inject lateinit var bar: Bar }
public void injectExampleActivity(ExampleActivity instance) { BaseActivity_MembersInjector.injectBar(instance, new Bar()); ExampleActivity_MembersInjector.injectBar(instance, new Bar()); } } @AndroidEntryPoint class ExampleActivity : BaseActivity() { @Inject lateinit var bar: Bar } public abstract class BaseActivity extends ComponentActivity { @Inject Bar bar; } @Inject ݃ ࢲ۽ ܲ ёܳ ࢤࢿೠ.
class Bar @Inject constructor() @EntryPoint @InstallIn(SingletonComponent::class) interface ExampleEntryPoint { fun bar(): Bar } val entryPoint = EntryPointAccessors.fromApplication( context = context, entryPoint = ExampleEntryPoint::class.java, ) val bar: Bar = entryPoint.bar()
-------------------------------------------------------------------------------- // Generated by Hilt public final class ExampleApplication_HiltComponents { @Component(modules = { ... }) @Singleton public abstract static class SingletonC implements SingletonComponent, GeneratedComponent, ExampleEntryPoint { } } // -------------------------------------------------------------------------------- // Generated by Dagger public final class DaggerExampleApplication_HiltComponents_SingletonC { private static final class SingletonCImpl extends SingletonC { public Bar bar() { return new Bar(); } } ... } (1) EntryPointо ઓࢿ Ӓېী ୶оػ.
Baz class BazImpl(bar: Bar) : Baz interface Bar class BarImpl(foo: Foo) : Bar interface Foo class FooImpl() : Foo interface Qux class QuxImpl(baz: Baz) : Qux بݫੋ ݽٕ ৈۤݶ, inte rf aceܳ য٣ী ىঠ ೡө???
Foo) : Bar interface Foo class FooImpl() : Foo interface Qux class QuxImpl(bar: Bar) : Qux interface Bar inte rf aceܳ ӡ ਤо গݒೞ… :domain-baz interface Baz class BazImpl(bar: Bar) : Baz interface Bar
:domain-baz :domain-bar-impl interface Bar class BarImpl(foo: Foo) : Bar -> interface Qux class QuxImpl(bar: Bar) : Qux @Module interface Baz class BazImpl(bar: Bar) : Baz