fixed docs and code

This commit is contained in:
Sergey Penkovsky
2021-12-10 22:04:51 +03:00
parent 7a53844c7d
commit 58245fb665
7 changed files with 43 additions and 43 deletions

View File

@@ -7,7 +7,7 @@
Binding is a custom instance configurator that contains methods for configuring a dependency.
There are two main methods for initializing a custom instance `toInstance ()` and `toProvide ()` and auxiliary `withName ()` and `singeltone ()`.
There are two main methods for initializing a custom instance `toInstance()` and `toProvide()` and auxiliary `withName()` and `singleton()`.
`toInstance()` - takes a initialized instance
@@ -36,7 +36,7 @@ Example:
// instance initialization like singleton
Binding<String>().toInstance("hello world");
// or
Binding<String>().toProvide(() => "hello world").singeltone();
Binding<String>().toProvide(() => "hello world").singleton();
```
@@ -111,7 +111,7 @@ class FeatureModule extends Module {
),
),
)
.singeltone();
.singleton();
bind<DataBloc>().toProvide(
() => DataBloc(
currentScope.resolve<DataRepository>(named: "networkRepo"),

View File

@@ -7,7 +7,7 @@
Binding is a custom instance configurator that contains methods for configuring a dependency.
There are two main methods for initializing a custom instance `toInstance ()` and `toProvide ()` and auxiliary `withName ()` and `singeltone ()`.
There are two main methods for initializing a custom instance `toInstance ()` and `toProvide ()` and auxiliary `withName ()` and `singleton ()`.
`toInstance()` - takes a initialized instance
@@ -15,7 +15,7 @@ There are two main methods for initializing a custom instance `toInstance ()` an
`withName()` - takes a string to name the instance. By this name, it will be possible to extract instance from the DI container
`singeltone()` - sets a flag in the Binding that tells the DI container that there is only one dependency.
`singleton()` - sets a flag in the Binding that tells the DI container that there is only one dependency.
Example:
@@ -36,7 +36,7 @@ Example:
// instance initialization like singleton
Binding<String>().toInstance("hello world");
// or
Binding<String>().toProvide(() => "hello world").singeltone();
Binding<String>().toProvide(() => "hello world").singleton();
```
@@ -111,7 +111,7 @@ class FeatureModule extends Module {
),
),
)
.singeltone();
.singleton();
bind<DataBloc>().toProvide(
() => DataBloc(
currentScope.resolve<DataRepository>(named: "networkRepo"),

View File

@@ -7,7 +7,7 @@
Binding - по сути это конфигуратор для пользовательского instance, который соддержит методы для конфигурирования зависимости.
Есть два основных метода для инициализации пользовательского instance `toInstance()` и `toProvide()` и вспомогательных `withName()` и `singeltone()`.
Есть два основных метода для инициализации пользовательского instance `toInstance()` и `toProvide()` и вспомогательных `withName()` и `singleton()`.
`toInstance()` - принимает готовый экземпляр
@@ -15,7 +15,7 @@ Binding - по сути это конфигуратор для пользов
`withName()` - принимает строку для именования экземпляра. По этому имени можно будет извлечь instance из DI контейнера
`singeltone()` - устанавливает флаг в Binding, который говорит DI контейнеру, что зависимость одна.
`singleton()` - устанавливает флаг в Binding, который говорит DI контейнеру, что зависимость одна.
Пример:
@@ -36,7 +36,7 @@ Binding - по сути это конфигуратор для пользов
// инициализация экземпляра, как сингелтон
Binding<String>().toInstance("hello world");
// или
Binding<String>().toProvide(() => "hello world").singeltone();
Binding<String>().toProvide(() => "hello world").singleton();
```
@@ -111,7 +111,7 @@ class FeatureModule extends Module {
),
),
)
.singeltone();
.singleton();
bind<DataBloc>().toProvide(
() => DataBloc(
currentScope.resolve<DataRepository>(named: "networkRepo"),

View File

@@ -50,7 +50,7 @@ class FeatureModule extends Module {
),
),
)
.singeltone();
.singleton();
bind<DataBloc>().toProvide(
() => DataBloc(
currentScope.resolve<DataRepository>(named: "networkRepo"),

View File

@@ -27,7 +27,7 @@ class FeatureModule extends Module {
),
),
)
.singeltone();
.singleton();
bind<DataBloc>().toProvide(
() => DataBloc(
currentScope.resolve<DataRepository>(named: 'networkRepo'),

View File

@@ -22,7 +22,7 @@ class Binding<T> {
late String _name;
T? _instance;
T? Function()? _provider;
late bool _isSingeltone = false;
late bool _isSingleton = false;
late bool _isNamed = false;
Binding() {
@@ -52,7 +52,7 @@ class Binding<T> {
/// ENG: The method checks the singleton instance or not.
///
/// return [bool]
bool get isSingeltone => _isSingeltone;
bool get isSingleton => _isSingleton;
/// RU: Метод проверяет именован экземпляр или нет.
/// ENG: The method checks whether the instance is named or not.
@@ -77,7 +77,7 @@ class Binding<T> {
Binding<T> toInstance(T value) {
_mode = Mode.INSTANCE;
_instance = value;
_isSingeltone = true;
_isSingleton = true;
return this;
}
@@ -96,7 +96,7 @@ class Binding<T> {
///
/// return [Binding]
Binding<T> singleton() {
_isSingeltone = true;
_isSingleton = true;
return this;
}
@@ -111,7 +111,7 @@ class Binding<T> {
///
/// return [T]
T? get provider {
if (_isSingeltone) {
if (_isSingleton) {
_instance ??= _provider?.call();
return _instance;
}

View File

@@ -16,11 +16,11 @@ void main() {
expect(binding.mode, Mode.INSTANCE);
});
test('Binding check singeltone', () {
test('Binding check singleton', () {
final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue);
expect(binding.isSingeltone, true);
expect(binding.isSingleton, true);
});
test('Binding check value', () {
@@ -59,12 +59,12 @@ void main() {
expect(binding.key, int);
});
test('Binding check singeltone', () {
test('Binding check singleton', () {
final expectedValue = 5;
final binding =
Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.isSingeltone, true);
expect(binding.isSingleton, true);
});
test('Binding check value', () {
@@ -106,11 +106,11 @@ void main() {
expect(binding.mode, Mode.PROVIDER_INSTANCE);
});
test('Binding check singeltone', () {
test('Binding check singleton', () {
final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.isSingeltone, false);
expect(binding.isSingleton, false);
});
test('Binding check value', () {
@@ -151,13 +151,13 @@ void main() {
expect(binding.key, int);
});
test('Binding check singeltone', () {
test('Binding check singleton', () {
final expectedValue = 5;
final binding = Binding<int>()
.withName('expectedValue')
.toProvide(() => expectedValue);
expect(binding.isSingeltone, false);
expect(binding.isSingleton, false);
});
test('Binding check value', () {
@@ -188,33 +188,33 @@ void main() {
});
});
group('Check singeltone provide.', () {
group('Check singleton provide.', () {
group('Without name.', () {
test('Binding resolves null', () {
final binding = Binding<int>().singeltone();
final binding = Binding<int>().singleton();
expect(binding.provider, null);
});
test('Binding check mode', () {
final expectedValue = 5;
final binding =
Binding<int>().toProvide(() => expectedValue).singeltone();
Binding<int>().toProvide(() => expectedValue).singleton();
expect(binding.mode, Mode.PROVIDER_INSTANCE);
});
test('Binding check singeltone', () {
test('Binding check singleton', () {
final expectedValue = 5;
final binding =
Binding<int>().toProvide(() => expectedValue).singeltone();
Binding<int>().toProvide(() => expectedValue).singleton();
expect(binding.isSingeltone, true);
expect(binding.isSingleton, true);
});
test('Binding check value', () {
final expectedValue = 5;
final binding =
Binding<int>().toProvide(() => expectedValue).singeltone();
Binding<int>().toProvide(() => expectedValue).singleton();
expect(binding.provider, expectedValue);
});
@@ -222,14 +222,14 @@ void main() {
test('Binding resolves value', () {
final expectedValue = 5;
final binding =
Binding<int>().toProvide(() => expectedValue).singeltone();
Binding<int>().toProvide(() => expectedValue).singleton();
expect(binding.provider, expectedValue);
});
});
group('With name.', () {
test('Binding resolves null', () {
final binding = Binding<int>().withName('expectedValue').singeltone();
final binding = Binding<int>().withName('expectedValue').singleton();
expect(binding.provider, null);
});
@@ -238,7 +238,7 @@ void main() {
final binding = Binding<int>()
.withName('expectedValue')
.toProvide(() => expectedValue)
.singeltone();
.singleton();
expect(binding.mode, Mode.PROVIDER_INSTANCE);
});
@@ -248,19 +248,19 @@ void main() {
final binding = Binding<int>()
.withName('expectedValue')
.toProvide(() => expectedValue)
.singeltone();
.singleton();
expect(binding.key, int);
});
test('Binding check singeltone', () {
test('Binding check singleton', () {
final expectedValue = 5;
final binding = Binding<int>()
.withName('expectedValue')
.toProvide(() => expectedValue)
.singeltone();
.singleton();
expect(binding.isSingeltone, true);
expect(binding.isSingleton, true);
});
test('Binding check value', () {
@@ -268,7 +268,7 @@ void main() {
final binding = Binding<int>()
.withName('expectedValue')
.toProvide(() => expectedValue)
.singeltone();
.singleton();
expect(binding.provider, expectedValue);
});
@@ -278,7 +278,7 @@ void main() {
final binding = Binding<int>()
.withName('expectedValue')
.toProvide(() => expectedValue)
.singeltone();
.singleton();
expect(binding.name, 'expectedValue');
});
@@ -288,7 +288,7 @@ void main() {
final binding = Binding<int>()
.withName('expectedValue')
.toProvide(() => expectedValue)
.singeltone();
.singleton();
expect(binding.provider, expectedValue);
});
});