Binding class abstract
An interface to define dependency injection rules for routes or specific flows in GetXify v5.0.0.
Classes implementing Binding override the dependencies method to register controllers, services, or other objects before a route/page is built or when entering a specific scope.
Options for defining bindings:
- Class-based Binding:
class HomeBinding extends Binding {
@override
void dependencies() {
Get.put(HomeController());
}
}
- Inline Direct Bindings (
Binding.put/Binding.lazyPut):
GetPage(
name: '/home',
page: () => HomePage(),
bindings: [
Binding.put(HomeController()),
Binding.lazyPut(() => UserController()),
],
);
- Inline Functional Builder (
Binding.builder):
GetPage(
name: '/home',
page: () => HomePage(),
bindings: [
Binding.builder(() {
Get.put(HomeController());
}),
],
);
Constructors
- Binding()
-
const
- Binding.builder(Function builder)
-
Creates a Binding using an inline builder callback.
Accepts either
void Function()orvoid Function(GetInterface i).factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dependencies(
) → void - Defines and registers dependencies.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
create<
S> (InstanceBuilderCallback< S> builder, {String? tag, bool permanent = false}) → Binding -
Creates a Binding that registers a factory
buildercreated on demand. -
lazyPut<
S> (InstanceBuilderCallback< S> builder, {String? tag, bool fenix = false}) → Binding -
Creates a Binding that lazily initializes
builderon first access. -
put<
S> (S dependency, {String? tag, bool permanent = false}) → Binding -
Creates a Binding that immediately registers
dependency.