AutoConfiguration class final
Declares a class as a source of automatic configuration.
This annotation marks a class that provides pods, services, or other application components that should be automatically discovered and registered by the framework during application startup.
π How it Works:
- The framework automatically scans all classes annotated with
@AutoConfiguration
during bootstrap. - Any methods within these classes annotated with
@Pod
are treated as factory methods and their return values are registered as pods in the application context. - Typically, this is used for library-level default configurations or framework-provided setups.
π― Target Use Cases:
- Automatically register commonly used pods (e.g.,
Logger
,HttpClient
) - Provide cross-cutting concerns (e.g., metrics, tracing)
- Reduce boilerplate in app-level configuration
π§ Requirements:
- The annotated class must have a public zero-argument constructor (if not using static methods).
@Pod
methods must return non-null values that will be added to the DI container.
π§ͺ Example:
@AutoConfiguration()
class DefaultInfrastructure {
@Pod()
Logger logger() => Logger();
@Pod()
HttpClient client() => HttpClient();
}
β οΈ Notes:
- If you donβt want a class to be automatically discovered,
use
@Configuration()
instead and import it manually. - Avoid putting app-specific configuration in an
@AutoConfiguration
class β it's meant for shared, reusable modules.
π Organization Tip:
Use this in reusable package-level configurations, such as:
logging_config.dart
database_auto_config.dart
http_auto_config.dart
π§ Related:
@Pod()
β Marks methods that return injectable components.@Configuration()
β Similar, but not auto-scanned; must be imported.
Applies to:
class
declarations only.
- Annotations
-
- @Target.new({TargetKind.classType})
Constructors
- AutoConfiguration([bool proxyPodMethods = true, ScopeMetadataResolver scopeResolver = const AnnotatedScopeMetadataResolver()])
-
Declares a class as a source of automatic configuration.
const
Properties
- hashCode β int
-
The hash code for this object.
no setterinherited
- proxyPodMethods β bool
-
Specify whether @Pod methods should get proxied in order to enforce pod lifecycle behavior.
finalinherited
- runtimeType β Type
-
A representation of the runtime type of the object.
no setterinherited
- scopeResolver β ScopeMetadataResolver
-
Specify the scope metadata resolver to use for resolving scope metadata.
finalinherited
Methods
-
equalizedProperties(
) β List< Object?> -
Mixin-style contract for value-based equality,
hashCode
, andtoString
. -
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