Compare commits

..

37 Commits
0.1.0 ... 0.1.2

Author SHA1 Message Date
Sergey Penkovsky
276d6bfb12 changed build version and updated changelog 2021-04-29 10:04:34 +03:00
Sergey Penkovsky
0e37d7f222 fixed cide analizer warnings 2021-04-29 10:02:32 +03:00
Sergey Penkovsky
5ea3744961 changed build version 2021-04-28 09:34:17 +03:00
Sergey Penkovsky
37c676cefa fixed warnings 2021-04-28 09:31:49 +03:00
Sergey Penkovsky
8a9fb1d55c updated libs, fixed warnings 2021-04-28 09:30:32 +03:00
Sergey Penkovsky
8f86662c9b changed build version 2021-04-28 08:22:08 +03:00
Sergey Penkovsky
dcdfce41db added readme for example 2021-04-28 08:20:45 +03:00
Sergey Penkovsky
c2f2577cc6 fixed description 2021-04-28 08:01:42 +03:00
Sergey Penkovsky
93f431ce93 Update quick_start_ru.md 2021-04-27 13:06:44 +03:00
Sergey Penkovsky
5462f9da07 updated pubspec 2021-04-27 06:17:54 +03:00
Sergey Penkovsky
ac30908f2d update version 2021-04-27 06:15:34 +03:00
Sergey Penkovsky
4cfca7c063 update version 2021-04-27 06:14:47 +03:00
Sergey Penkovsky
5afb8bda35 fixed link to documentation 2021-04-27 06:13:30 +03:00
Sergey Penkovsky
86c58191e5 Merge branch 'renamed_package' into 'master'
renamed package

See merge request pese/dart_di!2
2021-04-26 11:58:32 +00:00
Sergey Penkovsky
f3b1ee84b2 renamed package 2021-04-26 14:56:09 +03:00
Sergey Penkovsky
b6a4b86b19 fixed pubspec 2021-04-26 14:19:46 +03:00
Sergey Penkovsky
a20d153c1a fixed pubspec 2021-04-26 14:15:15 +03:00
Sergey Penkovsky
b621865e82 fixed pubspec 2021-04-26 14:11:52 +03:00
Sergey Penkovsky
4f127751d8 added home site 2021-04-26 14:10:03 +03:00
Sergey Penkovsky
1fb6db6dec Merge branch 'next' into 'master'
Next

See merge request pese/dart_di!1
2021-04-26 07:49:43 +00:00
Sergey Penkovsky
565fb3e682 added license header for src. Added changelog 2021-04-26 10:47:52 +03:00
Sergey Penkovsky
de404d4ee1 refactored di library. 2021-04-26 10:47:52 +03:00
Sergey Penkovsky
35879380d0 fixed binding and writed unit tests 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
bab560a856 fixed binding and writed unit tests 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
98f12c5eb7 refactored code and implemented unit tests 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
2568414a1b implemented doc 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
1ddbb74e3f added documentation 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
e102b15022 added documents 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
ec75ad9172 added documentation 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
ed0c2fae53 added documentation 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
4302d733ba added documentation 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
c9ddc2ffa8 fixed resolve method 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
b2b66bdcfd fixed example 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
6a2d86c83c implemented expiremental di with new api 2021-04-26 10:47:16 +03:00
Sergey Penkovsky
2d6fdbe04c Update README.md 2021-04-07 14:57:43 +00:00
Sergey Penkovsky
35a9478446 upgraded code for nullsafety 2021-03-27 19:50:47 +03:00
Sergey Penkovsky
0e3c5037fb Добавить .gitlab-ci.yml 2020-11-12 19:27:11 +00:00
17 changed files with 356 additions and 203 deletions

View File

@@ -1,4 +1,19 @@
# Changelog
0.1.2 Fixed warnings in code
---
0.1.1+2 Updated libraries and fixed warnings
---
0.1.1+1 Updated pubspec and readme.md
---
0.1.1 Updated pubspec
--- ---
0.1.0 Initial release 0.1.0 Initial release

View File

@@ -1,4 +1,4 @@
# dart_di # cherrypick
Experimental development of DI in the Dart language Experimental development of DI in the Dart language

1
analysis_options.yaml Normal file
View File

@@ -0,0 +1 @@
include: package:pedantic/analysis_options.yaml

View File

@@ -65,7 +65,7 @@ Example:
```dart ```dart
// open main scope // open main scope
final rootScope = DartDi.openRootScope(); final rootScope = Cherrypick.openRootScope();
// initializing scope with a custom module // initializing scope with a custom module
rootScope.installModules([AppModule()]); rootScope.installModules([AppModule()]);
@@ -76,7 +76,7 @@ Example:
final str = rootScope.tryResolve<String>(); final str = rootScope.tryResolve<String>();
// close main scope // close main scope
DartDi.closeRootScope(); Cherrypick.closeRootScope();
``` ```
## Example app ## Example app
@@ -85,8 +85,8 @@ Example:
```dart ```dart
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:dart_di/experimental/scope.dart'; import 'package:cherrypick/scope.dart';
import 'package:dart_di/experimental/module.dart'; import 'package:cherrypick/module.dart';
class AppModule extends Module { class AppModule extends Module {
@override @override

View File

@@ -65,7 +65,7 @@ Scope - это контейнер, который хранит все дерев
```dart ```dart
// открыть главный scope // открыть главный scope
final rootScope = DartDi.openRootScope(); final rootScope = CherryPick.openRootScope();
// инициализация scope пользовательским модулем // инициализация scope пользовательским модулем
rootScope.installModules([AppModule()]); rootScope.installModules([AppModule()]);
@@ -76,7 +76,7 @@ Scope - это контейнер, который хранит все дерев
final str = rootScope.tryResolve<String>(); final str = rootScope.tryResolve<String>();
// закрыть главный scope // закрыть главный scope
DartDi.closeRootScope(); Cherrypick.closeRootScope();
``` ```
## Пример приложения ## Пример приложения
@@ -85,8 +85,8 @@ Scope - это контейнер, который хранит все дерев
```dart ```dart
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:dart_di/experimental/scope.dart'; import 'package:cherrypick/scope.dart';
import 'package:dart_di/experimental/module.dart'; import 'package:cherrypick/module.dart';
class AppModule extends Module { class AppModule extends Module {
@override @override

133
example/README.md Normal file
View File

@@ -0,0 +1,133 @@
# Example
pubspec.yaml:
```yaml
name: example
version: 1.0.0
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
cherrypick:
path: ../
dev_dependencies:
test: ^1.16.8
```
main.dart:
```dart
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:cherrypick/scope.dart';
import 'package:cherrypick/module.dart';
class AppModule extends Module {
@override
void builder(Scope currentScope) {
bind<ApiClient>().withName("apiClientMock").toInstance(ApiClientMock());
bind<ApiClient>().withName("apiClientImpl").toInstance(ApiClientImpl());
}
}
class FeatureModule extends Module {
bool isMock;
FeatureModule({required this.isMock});
@override
void builder(Scope currentScope) {
bind<DataRepository>()
.withName("networkRepo")
.toProvide(
() => NetworkDataRepository(
currentScope.resolve<ApiClient>(
named: isMock ? "apiClientMock" : "apiClientImpl",
),
),
)
.singeltone();
bind<DataBloc>().toProvide(
() => DataBloc(
currentScope.resolve<DataRepository>(named: "networkRepo"),
),
);
}
}
void main() async {
final scope = openRootScope().installModules([
AppModule(),
]);
final subScope = scope
.openSubScope("featureScope")
.installModules([FeatureModule(isMock: true)]);
final dataBloc = subScope.resolve<DataBloc>();
dataBloc.data.listen((d) => print('Received data: $d'),
onError: (e) => print('Error: $e'), onDone: () => print('DONE'));
await dataBloc.fetchData();
}
class DataBloc {
final DataRepository _dataRepository;
Stream<String> get data => _dataController.stream;
StreamController<String> _dataController = new StreamController.broadcast();
DataBloc(this._dataRepository);
Future<void> fetchData() async {
try {
_dataController.sink.add(await _dataRepository.getData());
} catch (e) {
_dataController.sink.addError(e);
}
}
void dispose() {
_dataController.close();
}
}
abstract class DataRepository {
Future<String> getData();
}
class NetworkDataRepository implements DataRepository {
final ApiClient _apiClient;
final _token = 'token';
NetworkDataRepository(this._apiClient);
@override
Future<String> getData() async => await _apiClient.sendRequest(
url: 'www.google.com', token: _token, requestBody: {'type': 'data'});
}
abstract class ApiClient {
Future sendRequest({@required String url, String token, Map requestBody});
}
class ApiClientMock implements ApiClient {
@override
Future sendRequest(
{@required String? url, String? token, Map? requestBody}) async {
return 'Local Data';
}
}
class ApiClientImpl implements ApiClient {
@override
Future sendRequest(
{@required String? url, String? token, Map? requestBody}) async {
return 'Network data';
}
}
```

View File

@@ -1,13 +1,13 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:dart_di/scope.dart'; import 'package:cherrypick/scope.dart';
import 'package:dart_di/module.dart'; import 'package:cherrypick/module.dart';
class AppModule extends Module { class AppModule extends Module {
@override @override
void builder(Scope currentScope) { void builder(Scope currentScope) {
bind<ApiClient>().withName("apiClientMock").toInstance(ApiClientMock()); bind<ApiClient>().withName('apiClientMock').toInstance(ApiClientMock());
bind<ApiClient>().withName("apiClientImpl").toInstance(ApiClientImpl()); bind<ApiClient>().withName('apiClientImpl').toInstance(ApiClientImpl());
} }
} }
@@ -19,18 +19,18 @@ class FeatureModule extends Module {
@override @override
void builder(Scope currentScope) { void builder(Scope currentScope) {
bind<DataRepository>() bind<DataRepository>()
.withName("networkRepo") .withName('networkRepo')
.toProvide( .toProvide(
() => NetworkDataRepository( () => NetworkDataRepository(
currentScope.resolve<ApiClient>( currentScope.resolve<ApiClient>(
named: isMock ? "apiClientMock" : "apiClientImpl", named: isMock ? 'apiClientMock' : 'apiClientImpl',
), ),
), ),
) )
.singeltone(); .singeltone();
bind<DataBloc>().toProvide( bind<DataBloc>().toProvide(
() => DataBloc( () => DataBloc(
currentScope.resolve<DataRepository>(named: "networkRepo"), currentScope.resolve<DataRepository>(named: 'networkRepo'),
), ),
); );
} }
@@ -42,7 +42,7 @@ void main() async {
]); ]);
final subScope = scope final subScope = scope
.openSubScope("featureScope") .openSubScope('featureScope')
.installModules([FeatureModule(isMock: true)]); .installModules([FeatureModule(isMock: true)]);
final dataBloc = subScope.resolve<DataBloc>(); final dataBloc = subScope.resolve<DataBloc>();
@@ -56,7 +56,7 @@ class DataBloc {
final DataRepository _dataRepository; final DataRepository _dataRepository;
Stream<String> get data => _dataController.stream; Stream<String> get data => _dataController.stream;
StreamController<String> _dataController = new StreamController.broadcast(); final StreamController<String> _dataController = StreamController.broadcast();
DataBloc(this._dataRepository); DataBloc(this._dataRepository);

View File

@@ -2,13 +2,14 @@ name: example
version: 1.0.0 version: 1.0.0
author: "Sergey Penkovsky <sergey.penkovsky@gmail.com>" author: "Sergey Penkovsky <sergey.penkovsky@gmail.com>"
homepage: localhost homepage: localhost
publish_to: none
environment: environment:
sdk: ">=2.12.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"
dependencies: dependencies:
dart_di: cherrypick:
path: ../ path: ../
dev_dependencies: dev_dependencies:

View File

@@ -1,15 +1,15 @@
/** ///
* Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com> /// Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com>
* Licensed under the Apache License, Version 2.0 (the "License"); /// Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. /// you may not use this file except in compliance with the License.
* You may obtain a copy of the License at /// You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 /// http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software /// Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, /// distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and /// See the License for the specific language governing permissions and
* limitations under the License. /// limitations under the License.
*/ ///
enum Mode { SIMPLE, INSTANCE, PROVIDER_INSTANCE } enum Mode { SIMPLE, INSTANCE, PROVIDER_INSTANCE }
@@ -20,8 +20,8 @@ class Binding<T> {
late Mode _mode; late Mode _mode;
late Type _key; late Type _key;
late String _name; late String _name;
T? _instance = null; T? _instance;
T? Function()? _provider = null; T? Function()? _provider;
late bool _isSingeltone = false; late bool _isSingeltone = false;
late bool _isNamed = false; late bool _isNamed = false;

View File

@@ -1,19 +1,19 @@
/** ///
* Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com> /// Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com>
* Licensed under the Apache License, Version 2.0 (the "License"); /// Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. /// you may not use this file except in compliance with the License.
* You may obtain a copy of the License at /// You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 /// http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software /// Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, /// distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and /// See the License for the specific language governing permissions and
* limitations under the License. /// limitations under the License.
*/ ///
library dart_di; library dart_di;
export 'package:dart_di/scope.dart'; export 'package:cherrypick/scope.dart';
export 'package:dart_di/module.dart'; export 'package:cherrypick/module.dart';
export 'package:dart_di/binding.dart'; export 'package:cherrypick/binding.dart';
export 'package:dart_di/di.dart'; export 'package:cherrypick/di.dart';

View File

@@ -1,28 +1,27 @@
/** ///
* Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com> /// Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com>
* Licensed under the Apache License, Version 2.0 (the "License"); /// Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. /// you may not use this file except in compliance with the License.
* You may obtain a copy of the License at /// You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 /// http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software /// Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, /// distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and /// See the License for the specific language governing permissions and
* limitations under the License. /// limitations under the License.
*/ ///
import 'package:dart_di/scope.dart';
Scope? _rootScope = null; import 'package:cherrypick/scope.dart';
class DartDi { Scope? _rootScope;
class CherryPick {
/// RU: Метод открывает главный [Scope]. /// RU: Метод открывает главный [Scope].
/// ENG: The method opens the main [Scope]. /// ENG: The method opens the main [Scope].
/// ///
/// return /// return
static Scope openRootScope() { static Scope openRootScope() {
if (_rootScope == null) { _rootScope ??= Scope(null);
_rootScope = Scope(null);
}
return _rootScope!; return _rootScope!;
} }

View File

@@ -1,17 +1,17 @@
/** ///
* Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com> /// Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com>
* Licensed under the Apache License, Version 2.0 (the "License"); /// Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. /// you may not use this file except in compliance with the License.
* You may obtain a copy of the License at /// You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 /// http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software /// Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, /// distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and /// See the License for the specific language governing permissions and
* limitations under the License. /// limitations under the License.
*/ ///
import 'package:dart_di/scope.dart'; import 'package:cherrypick/scope.dart';
abstract class Factory<T> { abstract class Factory<T> {
T createInstance(Scope scope); T createInstance(Scope scope);

View File

@@ -1,20 +1,20 @@
/** ///
* Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com> /// Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com>
* Licensed under the Apache License, Version 2.0 (the "License"); /// Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. /// you may not use this file except in compliance with the License.
* You may obtain a copy of the License at /// You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 /// http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software /// Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, /// distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and /// See the License for the specific language governing permissions and
* limitations under the License. /// limitations under the License.
*/ ///
import 'dart:collection'; import 'dart:collection';
import 'package:dart_di/binding.dart'; import 'package:cherrypick/binding.dart';
import 'package:dart_di/scope.dart'; import 'package:cherrypick/scope.dart';
/// RU: Класс Module является основой для пользовательских модулей. /// RU: Класс Module является основой для пользовательских модулей.
/// Этот класс нужен для инициализации [Scope]. /// Этот класс нужен для инициализации [Scope].

View File

@@ -1,20 +1,20 @@
/** ///
* Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com> /// Copyright 2021 Sergey Penkovsky <sergey.penkovsky@gmail.com>
* Licensed under the Apache License, Version 2.0 (the "License"); /// Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. /// you may not use this file except in compliance with the License.
* You may obtain a copy of the License at /// You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 /// http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software /// Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, /// distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and /// See the License for the specific language governing permissions and
* limitations under the License. /// limitations under the License.
*/ ///
import 'dart:collection'; import 'dart:collection';
import 'package:dart_di/binding.dart'; import 'package:cherrypick/binding.dart';
import 'package:dart_di/module.dart'; import 'package:cherrypick/module.dart';
Scope openRootScope() => Scope(null); Scope openRootScope() => Scope(null);
@@ -103,8 +103,8 @@ class Scope {
T? tryResolve<T>({String? named}) { T? tryResolve<T>({String? named}) {
// 1 Поиск зависимости по всем модулям текущего скоупа // 1 Поиск зависимости по всем модулям текущего скоупа
if (_modulesList.isNotEmpty) { if (_modulesList.isNotEmpty) {
for (Module module in _modulesList) { for (var module in _modulesList) {
for (Binding binding in module.bindingSet) { for (var binding in module.bindingSet) {
if (binding.key == T && if (binding.key == T &&
((!binding.isNamed && named == null) || ((!binding.isNamed && named == null) ||
(binding.isNamed && named == binding.name))) { (binding.isNamed && named == binding.name))) {

View File

@@ -1,8 +1,10 @@
name: dart_di name: cherrypick
description: Experimental Dependency Injection library. description: Cherrypick is a small dependency injection (DI) library for dart/flutter projects.
version: 0.1.0 version: 0.1.2
author: Sergey Penkovsky <sergey.penkovsky@gmail.com> homepage: https://github.com/pese-git/cherrypick
homepage: locahost documentation: https://github.com/pese-git/cherrypick/wiki
repository: https://github.com/pese-git/cherrypick
issue_tracker: https://github.com/pese-git/cherrypick/issues
environment: environment:
sdk: ">=2.12.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"
@@ -11,6 +13,8 @@ dependencies:
meta: ^1.3.0 meta: ^1.3.0
dev_dependencies: dev_dependencies:
test: ^1.16.8 pedantic: ^1.11.0
mockito: ^5.0.3 test: ^1.17.2
mockito: ^5.0.6

View File

@@ -1,201 +1,201 @@
import 'package:dart_di/binding.dart'; import 'package:cherrypick/binding.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
group("Check instance.", () { group('Check instance.', () {
group("Without name.", () { group('Without name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>(); final binding = Binding<int>();
expect(binding.instance, null); expect(binding.instance, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue); final binding = Binding<int>().toInstance(expectedValue);
expect(binding.mode, Mode.INSTANCE); expect(binding.mode, Mode.INSTANCE);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue); final binding = Binding<int>().toInstance(expectedValue);
expect(binding.isSingeltone, true); expect(binding.isSingeltone, true);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue); final binding = Binding<int>().toInstance(expectedValue);
expect(binding.instance, expectedValue); expect(binding.instance, expectedValue);
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue); final binding = Binding<int>().toInstance(expectedValue);
expect(binding.instance, expectedValue); expect(binding.instance, expectedValue);
}); });
}); });
group("With name.", () { group('With name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>().withName("expectedValue"); final binding = Binding<int>().withName('expectedValue');
expect(binding.instance, null); expect(binding.instance, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.mode, Mode.INSTANCE); expect(binding.mode, Mode.INSTANCE);
}); });
test("Binding check key", () { test('Binding check key', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.key, int); expect(binding.key, int);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.isSingeltone, true); expect(binding.isSingeltone, true);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.instance, expectedValue); expect(binding.instance, expectedValue);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.name, "expectedValue"); expect(binding.name, 'expectedValue');
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.instance, expectedValue); expect(binding.instance, expectedValue);
}); });
}); });
}); });
group("Check provide.", () { group('Check provide.', () {
group("Without name.", () { group('Without name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>(); final binding = Binding<int>();
expect(binding.provider, null); expect(binding.provider, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue); final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.mode, Mode.PROVIDER_INSTANCE); expect(binding.mode, Mode.PROVIDER_INSTANCE);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue); final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.isSingeltone, false); expect(binding.isSingeltone, false);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue); final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue); final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
}); });
group("With name.", () { group('With name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>().withName("expectedValue"); final binding = Binding<int>().withName('expectedValue');
expect(binding.provider, null); expect(binding.provider, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.mode, Mode.PROVIDER_INSTANCE); expect(binding.mode, Mode.PROVIDER_INSTANCE);
}); });
test("Binding check key", () { test('Binding check key', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.key, int); expect(binding.key, int);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.isSingeltone, false); expect(binding.isSingeltone, false);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.name, "expectedValue"); expect(binding.name, 'expectedValue');
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
}); });
}); });
group("Check singeltone provide.", () { group('Check singeltone provide.', () {
group("Without name.", () { group('Without name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>().singeltone(); final binding = Binding<int>().singeltone();
expect(binding.provider, null); expect(binding.provider, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().toProvide(() => expectedValue).singeltone(); Binding<int>().toProvide(() => expectedValue).singeltone();
@@ -203,7 +203,7 @@ void main() {
expect(binding.mode, Mode.PROVIDER_INSTANCE); expect(binding.mode, Mode.PROVIDER_INSTANCE);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().toProvide(() => expectedValue).singeltone(); Binding<int>().toProvide(() => expectedValue).singeltone();
@@ -211,7 +211,7 @@ void main() {
expect(binding.isSingeltone, true); expect(binding.isSingeltone, true);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().toProvide(() => expectedValue).singeltone(); Binding<int>().toProvide(() => expectedValue).singeltone();
@@ -219,7 +219,7 @@ void main() {
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().toProvide(() => expectedValue).singeltone(); Binding<int>().toProvide(() => expectedValue).singeltone();
@@ -227,66 +227,66 @@ void main() {
}); });
}); });
group("With name.", () { group('With name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>().withName("expectedValue").singeltone(); final binding = Binding<int>().withName('expectedValue').singeltone();
expect(binding.provider, null); expect(binding.provider, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.mode, Mode.PROVIDER_INSTANCE); expect(binding.mode, Mode.PROVIDER_INSTANCE);
}); });
test("Binding check key", () { test('Binding check key', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.key, int); expect(binding.key, int);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.isSingeltone, true); expect(binding.isSingeltone, true);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.name, "expectedValue"); expect(binding.name, 'expectedValue');
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);

View File

@@ -1,28 +1,28 @@
import 'package:dart_di/module.dart'; import 'package:cherrypick/module.dart';
import 'package:dart_di/scope.dart'; import 'package:cherrypick/scope.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
group("Without parent scope.", () { group('Without parent scope.', () {
test('Parent scope is null.', () { test('Parent scope is null.', () {
final scope = new Scope(null); final scope = Scope(null);
expect(scope.parentScope, null); expect(scope.parentScope, null);
}); });
test('Open sub scope.', () { test('Open sub scope.', () {
final scope = new Scope(null); final scope = Scope(null);
final subScope = scope.openSubScope("subScope"); final subScope = scope.openSubScope('subScope');
expect(scope.openSubScope("subScope"), subScope); expect(scope.openSubScope('subScope'), subScope);
}); });
test("Container throws state error if the value can't be resolved", () { test("Container throws state error if the value can't be resolved", () {
final scope = new Scope(null); final scope = Scope(null);
expect(() => scope.resolve<String>(), throwsA(isA<StateError>())); expect(() => scope.resolve<String>(), throwsA(isA<StateError>()));
}); });
test('Container resolves value after adding a dependency', () { test('Container resolves value after adding a dependency', () {
final expectedValue = "test string"; final expectedValue = 'test string';
final scope = new Scope(null) final scope = Scope(null)
.installModules([TestModule<String>(value: expectedValue)]); .installModules([TestModule<String>(value: expectedValue)]);
expect(scope.resolve<String>(), expectedValue); expect(scope.resolve<String>(), expectedValue);
}); });
@@ -42,7 +42,7 @@ void main() {
throwsA(isA<StateError>())); throwsA(isA<StateError>()));
}); });
*/ */
test("Container resolve() returns a value from parent container.", () { test('Container resolve() returns a value from parent container.', () {
final expectedValue = 5; final expectedValue = 5;
final parentScope = Scope(null); final parentScope = Scope(null);
final scope = Scope(parentScope); final scope = Scope(parentScope);
@@ -52,10 +52,10 @@ void main() {
expect(scope.resolve<int>(), expectedValue); expect(scope.resolve<int>(), expectedValue);
}); });
test("Container resolve() returns a several value from parent container.", test('Container resolve() returns a several value from parent container.',
() { () {
final expectedIntValue = 5; final expectedIntValue = 5;
final expectedStringValue = "Hello world"; final expectedStringValue = 'Hello world';
final parentScope = Scope(null).installModules([ final parentScope = Scope(null).installModules([
TestModule<int>(value: expectedIntValue), TestModule<int>(value: expectedIntValue),
TestModule<String>(value: expectedStringValue) TestModule<String>(value: expectedStringValue)