mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 13:47:24 +00:00
Add parameter to provider
This commit is contained in:
@@ -86,8 +86,8 @@ class Scope {
|
||||
/// 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}) {
|
||||
var resolved = tryResolve<T>(named: named);
|
||||
T resolve<T>({String? named, dynamic param}) {
|
||||
var resolved = tryResolve<T>(named: named, param: param);
|
||||
if (resolved != null) {
|
||||
return resolved;
|
||||
} else {
|
||||
@@ -99,7 +99,7 @@ class Scope {
|
||||
/// RU: Возвращает найденную зависимость типа [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, dynamic param}) {
|
||||
// 1 Поиск зависимости по всем модулям текущего скоупа
|
||||
if (_modulesList.isNotEmpty) {
|
||||
for (var module in _modulesList) {
|
||||
@@ -112,6 +112,12 @@ class Scope {
|
||||
return binding.instance;
|
||||
case Mode.PROVIDER_INSTANCE:
|
||||
return binding.provider;
|
||||
case Mode.PROVIDER_WITH_PARAMS_INSTANCE:
|
||||
if (param == null) {
|
||||
throw StateError(
|
||||
'Param is null. Maybe you forget pass it');
|
||||
}
|
||||
return binding.providerWithParam(param);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user