Files
cherrypick/cherrypick_annotations/lib/src/inject.dart

44 lines
1.4 KiB
Dart
Raw Normal View History

2025-05-23 12:21:23 +03:00
//
// Copyright 2021 Sergey Penkovsky (sergey.penkovsky@gmail.com)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
2025-08-08 23:24:05 +03:00
// https://www.apache.org/licenses/LICENSE-2.0
2025-05-23 12:21:23 +03:00
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
2025-05-23 15:26:09 +03:00
import 'package:meta/meta.dart';
/// Marks a field for dependency injection by CherryPick's code generator.
2025-05-23 17:13:57 +03:00
///
/// Use `@inject()` on fields within a class marked with `@injectable()`.
/// Such fields will be automatically injected from the DI [Scope]
/// when using the generated mixin or calling `.injectFields()`.
2025-05-23 17:13:57 +03:00
///
/// Example:
2025-05-23 17:13:57 +03:00
/// ```dart
/// import 'package:cherrypick_annotations/cherrypick_annotations.dart';
///
/// @injectable()
/// class LoginScreen with _\$LoginScreen {
/// @inject()
/// late final AuthService authService;
///
/// @inject()
/// @named('main')
/// late final ApiClient api;
/// }
///
/// // After running build_runner, call:
/// // LoginScreen().injectFields();
2025-05-23 17:13:57 +03:00
/// ```
2025-05-23 15:26:09 +03:00
@experimental
2025-05-23 12:21:23 +03:00
final class inject {
/// Creates an [inject] annotation for field injection.
2025-05-23 12:21:23 +03:00
const inject();
}