Bindings and Providers
Overview
In the Infuse framework, bindings and providers are key concepts for managing and configuring dependencies. Bindings link a type to a provider, and providers define how instances of that type are created and managed.
Bindings
A Binding in Infuse is essentially a link between a type (class) and a provider. It tells the injector how to provide an instance of a specific class.
Key Features
Type Association: Each binding is associated with a specific type.
Provider Linkage: Bindings are linked to a provider which defines how to instantiate the type.
Providers
Providers in Infuse are responsible for providing instances of a type. They are a crucial part of the dependency injection process.
Key Features
Functional Interface:
Provider<T>
is a functional interface, allowing for lambda expressions or method references.Context-Aware: Providers receive a
Context<?>
object, giving them information about the injection context.Versatile Instance Creation: Providers can return new instances, singletons, eager singletons, or specific pre-existing instances.
Types of Providers
Instance Provider: Provides a specific instance.
Singleton Provider: Provides a singleton instance (created once and reused).
Eager Singleton Provider: Similar to Singleton but instantiated eagerly.
Custom Provider: Custom logic for instance creation, considering the context.
Last updated