2025-05-21 00:50:57 +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
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
// 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 08:21:11 +03:00
|
|
|
/// ENGLISH:
|
|
|
|
|
/// Annotation to specify that a new instance should be provided on each request.
|
2025-05-22 13:52:56 +03:00
|
|
|
///
|
2025-05-23 08:21:11 +03:00
|
|
|
/// Use the `@instance()` annotation for methods or classes in your DI module
|
|
|
|
|
/// to declare that the DI container must create a new object every time
|
|
|
|
|
/// the dependency is injected (i.e., no singleton behavior).
|
2025-05-22 13:52:56 +03:00
|
|
|
///
|
|
|
|
|
/// Example:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// @module()
|
|
|
|
|
/// abstract class AppModule extends Module {
|
|
|
|
|
/// @instance()
|
|
|
|
|
/// Foo foo() => Foo();
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// This will generate:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// final class $AppModule extends AppModule {
|
|
|
|
|
/// @override
|
|
|
|
|
/// void builder(Scope currentScope) {
|
|
|
|
|
/// bind<Foo>().toInstance(() => foo());
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2025-05-23 08:21:11 +03:00
|
|
|
///
|
|
|
|
|
/// RUSSIAN (Русский):
|
|
|
|
|
/// Аннотация для создания нового экземпляра при каждом запросе.
|
|
|
|
|
///
|
|
|
|
|
/// Используйте `@instance()` для методов или классов в DI-модуле,
|
|
|
|
|
/// чтобы указать, что контейнер внедрения зависимостей должен создавать
|
|
|
|
|
/// новый объект при каждом обращении к зависимости (то есть, не синглтон).
|
|
|
|
|
///
|
|
|
|
|
/// Пример:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// @module()
|
|
|
|
|
/// abstract class AppModule extends Module {
|
|
|
|
|
/// @instance()
|
|
|
|
|
/// Foo foo() => Foo();
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// Будет сгенерирован следующий код:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// final class $AppModule extends AppModule {
|
|
|
|
|
/// @override
|
|
|
|
|
/// void builder(Scope currentScope) {
|
|
|
|
|
/// bind<Foo>().toInstance(() => foo());
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2025-05-21 00:50:57 +03:00
|
|
|
// ignore: camel_case_types
|
2025-05-21 12:23:33 +03:00
|
|
|
final class instance {
|
2025-05-21 00:50:57 +03:00
|
|
|
const instance();
|
|
|
|
|
}
|