added documentation

This commit is contained in:
Sergey Penkovsky
2021-04-22 10:25:38 +03:00
parent 6d7a52f0fa
commit dce2f4f7a9

View File

@@ -8,6 +8,11 @@ Scope openRootScope() => Scope(null);
class Scope { class Scope {
final Scope? _parentScope; final Scope? _parentScope;
/// RU: Метод возвращает родительский [Scope].
///
/// ENG: The method returns the parent [Scope].
///
/// return [Scope]
Scope? get parentScope => _parentScope; Scope? get parentScope => _parentScope;
final Map<String, Scope> _scopeMap = HashMap(); final Map<String, Scope> _scopeMap = HashMap();
@@ -16,6 +21,11 @@ class Scope {
final Set<Module> _modulesList = HashSet(); final Set<Module> _modulesList = HashSet();
/// RU: Метод открывает дочерний (дополнительный) [Scope].
///
/// ENG: The method opens child (additional) [Scope].
///
/// return [Scope]
Scope openSubScope(String name) { Scope openSubScope(String name) {
final subScope = Scope(this); final subScope = Scope(this);
if (!_scopeMap.containsKey(name)) { if (!_scopeMap.containsKey(name)) {
@@ -24,28 +34,47 @@ class Scope {
return _scopeMap[name]!; return _scopeMap[name]!;
} }
/// RU: Метод закрывает дочерний (дополнительный) [Scope].
///
/// ENG: The method closes child (additional) [Scope].
///
/// return [Scope]
void closeSubScope(String name) { void closeSubScope(String name) {
_scopeMap.remove(name); _scopeMap.remove(name);
} }
/// RU: Метод инициализирует пользовательские модули в [Scope].
///
/// ENG: The method initializes custom modules in [Scope].
///
/// return [Scope]
Scope installModules(List<Module> modules) { Scope installModules(List<Module> modules) {
_modulesList.addAll(modules); _modulesList.addAll(modules);
modules.forEach((module) => module.builder(this)); modules.forEach((module) => module.builder(this));
return this; return this;
} }
/// RU: Метод удаляет пользовательские модули из [Scope].
///
/// ENG: This method removes custom modules from [Scope].
///
/// return [Scope]
Scope dropModules() { Scope dropModules() {
_modulesList.removeAll(_modulesList); _modulesList.removeAll(_modulesList);
return this; return this;
} }
/** /// RU: Возвращает найденную зависимость, определенную параметром типа [T].
* Возвращает найденную зависимость, определенную параметром типа [T]. /// Выдает [StateError], если зависимость не может быть разрешена.
* Выдает [StateError], если зависимость не может быть разрешена. /// Если вы хотите получить [null], если зависимость не может быть найдена,
* Если вы хотите получить [null], если зависимость не может быть найдена, /// то используйте вместо этого [tryResolve]
* то используйте вместо этого [tryResolve] /// return - возвращает объект типа [T] или [StateError]
* @return - возвращает объект типа [T] или [StateError] ///
*/ /// ENG: Returns the found dependency specified by the type parameter [T].
/// Throws [StateError] if the dependency cannot be resolved.
/// If you want to get [null] if the dependency cannot be found then use [tryResolve] instead
/// return - returns an object of type [T] or [StateError]
///
T resolve<T>({String? named}) { T resolve<T>({String? named}) {
var resolved = tryResolve<T>(named: named); var resolved = tryResolve<T>(named: named);
if (resolved != null) { if (resolved != null) {
@@ -56,9 +85,9 @@ class Scope {
} }
} }
/** /// RU: Возвращает найденную зависимость типа [T] или null, если она не может быть найдена.
* Возвращает найденную зависимость типа [T] или null, если она не может быть найдена. /// ENG: Returns found dependency of type [T] or null if it cannot be found.
*/ ///
T? tryResolve<T>({String? named}) { T? tryResolve<T>({String? named}) {
// 1 Поиск зависимости по всем модулям текущего скоупа // 1 Поиск зависимости по всем модулям текущего скоупа
if (_modulesList.isNotEmpty) { if (_modulesList.isNotEmpty) {