From 38d3c0db1891541fa8d917810ccb599954c8ee51 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Mon, 14 Apr 2025 20:46:02 +0200 Subject: [PATCH 1/9] fix: Add missing override annotation --- .../catalyst_builder_container/test/service_container_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalyst_builder_container/test/service_container_test.dart b/packages/catalyst_builder_container/test/service_container_test.dart index 997eba3..c62142f 100644 --- a/packages/catalyst_builder_container/test/service_container_test.dart +++ b/packages/catalyst_builder_container/test/service_container_test.dart @@ -237,6 +237,7 @@ abstract interface class _MarkerInterface { } class _ServiceThatRequiresParameter implements _MarkerInterface { + @override final String parameter; _ServiceThatRequiresParameter( From febd37669d3b926fd43fcd623583bd001173570d Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Mon, 14 Apr 2025 20:47:57 +0200 Subject: [PATCH 2/9] change: Rename ProviderNotBootedException to ContainerNotBootedException --- .../lib/src/service_container.dart | 2 +- .../test/service_container_test.dart | 2 +- .../src/exception/container_not_booted_exception.dart | 11 +++++++++++ .../lib/src/exception/exception.dart | 2 +- .../src/exception/provider_not_booted_exception.dart | 11 ----------- ....dart => container_not_booted_exception_test.dart} | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 packages/catalyst_builder_contracts/lib/src/exception/container_not_booted_exception.dart delete mode 100644 packages/catalyst_builder_contracts/lib/src/exception/provider_not_booted_exception.dart rename packages/catalyst_builder_contracts/test/unit/exception/{provider_not_booted_exception_test.dart => container_not_booted_exception_test.dart} (87%) diff --git a/packages/catalyst_builder_container/lib/src/service_container.dart b/packages/catalyst_builder_container/lib/src/service_container.dart index 05fd879..9ddbc42 100644 --- a/packages/catalyst_builder_container/lib/src/service_container.dart +++ b/packages/catalyst_builder_container/lib/src/service_container.dart @@ -107,7 +107,7 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry { void _ensureBoot() { if (_booted == false) { - throw const ProviderNotBootedException(); + throw const ContainerNotBootedException(); } } diff --git a/packages/catalyst_builder_container/test/service_container_test.dart b/packages/catalyst_builder_container/test/service_container_test.dart index c62142f..138eea0 100644 --- a/packages/catalyst_builder_container/test/service_container_test.dart +++ b/packages/catalyst_builder_container/test/service_container_test.dart @@ -20,7 +20,7 @@ void main() { resetServiceProvider(); expect( () => serviceProvider.resolve(), - throwsA(const TypeMatcher()), + throwsA(const TypeMatcher()), ); }); diff --git a/packages/catalyst_builder_contracts/lib/src/exception/container_not_booted_exception.dart b/packages/catalyst_builder_contracts/lib/src/exception/container_not_booted_exception.dart new file mode 100644 index 0000000..b8814f4 --- /dev/null +++ b/packages/catalyst_builder_contracts/lib/src/exception/container_not_booted_exception.dart @@ -0,0 +1,11 @@ +import 'catalyst_builder_exception.dart'; + +/// An exception that is thrown when resolving services on a not booted +/// ServiceContainer. +class ContainerNotBootedException extends CatalystBuilderException { + /// Creates a new [ContainerNotBootedException] object. + const ContainerNotBootedException() + : super( + 'Service provider was not booted. Call ServiceContainer.boot() first.', + ); +} diff --git a/packages/catalyst_builder_contracts/lib/src/exception/exception.dart b/packages/catalyst_builder_contracts/lib/src/exception/exception.dart index db3d6be..bc5113e 100644 --- a/packages/catalyst_builder_contracts/lib/src/exception/exception.dart +++ b/packages/catalyst_builder_contracts/lib/src/exception/exception.dart @@ -1,5 +1,5 @@ export 'catalyst_builder_exception.dart'; export 'dependency_not_found_exception.dart'; export 'provider_already_booted_exception.dart'; -export 'provider_not_booted_exception.dart'; +export 'container_not_booted_exception.dart'; export 'service_not_found_exception.dart'; diff --git a/packages/catalyst_builder_contracts/lib/src/exception/provider_not_booted_exception.dart b/packages/catalyst_builder_contracts/lib/src/exception/provider_not_booted_exception.dart deleted file mode 100644 index 3e35b07..0000000 --- a/packages/catalyst_builder_contracts/lib/src/exception/provider_not_booted_exception.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'catalyst_builder_exception.dart'; - -/// An exception that is thrown when resolving services on a not booted -/// ServiceProvider. -class ProviderNotBootedException extends CatalystBuilderException { - /// Creates a new [ProviderNotBootedException] object. - const ProviderNotBootedException() - : super( - 'Service provider was not booted. Call ServiceProvider.boot() first.', - ); -} diff --git a/packages/catalyst_builder_contracts/test/unit/exception/provider_not_booted_exception_test.dart b/packages/catalyst_builder_contracts/test/unit/exception/container_not_booted_exception_test.dart similarity index 87% rename from packages/catalyst_builder_contracts/test/unit/exception/provider_not_booted_exception_test.dart rename to packages/catalyst_builder_contracts/test/unit/exception/container_not_booted_exception_test.dart index 98b0c52..a0114d7 100644 --- a/packages/catalyst_builder_contracts/test/unit/exception/provider_not_booted_exception_test.dart +++ b/packages/catalyst_builder_contracts/test/unit/exception/container_not_booted_exception_test.dart @@ -3,7 +3,7 @@ import 'package:test/test.dart'; void main() { test('constructor', () { - var ex = const ProviderNotBootedException(); + var ex = const ContainerNotBootedException(); expect(ex, const TypeMatcher()); expect( ex.message, From b244e7cbd873b81d2bfd63652e138ffde8992b64 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Mon, 14 Apr 2025 20:57:03 +0200 Subject: [PATCH 3/9] change: Rename ProviderAlreadyBootedException to ContainerAlreadyBootedException --- .../lib/src/service_container.dart | 4 ++-- .../test/service_container_test.dart | 5 ++--- ...ception.dart => container_already_booted_exception.dart} | 6 +++--- .../lib/src/exception/exception.dart | 2 +- ...st.dart => container_already_booted_exception_test.dart} | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) rename packages/catalyst_builder_contracts/lib/src/exception/{provider_already_booted_exception.dart => container_already_booted_exception.dart} (55%) rename packages/catalyst_builder_contracts/test/unit/exception/{provider_already_booted_exception_test.dart => container_already_booted_exception_test.dart} (84%) diff --git a/packages/catalyst_builder_container/lib/src/service_container.dart b/packages/catalyst_builder_container/lib/src/service_container.dart index 9ddbc42..ec262e2 100644 --- a/packages/catalyst_builder_container/lib/src/service_container.dart +++ b/packages/catalyst_builder_container/lib/src/service_container.dart @@ -97,7 +97,7 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry { @override void boot() { if (_booted) { - throw const ProviderAlreadyBootedException(); + throw const ContainerAlreadyBootedException(); } _booted = true; for (var type in _preloadedTypes) { @@ -169,7 +169,7 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry { @override void applyPlugin(ServiceProviderPlugin plugin) { if (_booted) { - throw const ProviderAlreadyBootedException(); + throw const ContainerAlreadyBootedException(); } _appliedPlugins.add(plugin); _knownServices.addAll(plugin.provideKnownServices(this)); diff --git a/packages/catalyst_builder_container/test/service_container_test.dart b/packages/catalyst_builder_container/test/service_container_test.dart index 138eea0..80b0ce8 100644 --- a/packages/catalyst_builder_container/test/service_container_test.dart +++ b/packages/catalyst_builder_container/test/service_container_test.dart @@ -27,7 +27,7 @@ void main() { test('double boot should throw an exception', () { expect( () => serviceProvider.boot(), - throwsA(const TypeMatcher()), + throwsA(const TypeMatcher()), ); }); @@ -287,8 +287,7 @@ class _MySelfRegisteredService implements _SelfRegisteredService { class _ServiceWithTaggedDependencies { final List dependencies; - _ServiceWithTaggedDependencies( - @Inject(tag: #tagToInject) List this.dependencies); + _ServiceWithTaggedDependencies(@Inject(tag: #tagToInject) this.dependencies); } class _PreloadService { diff --git a/packages/catalyst_builder_contracts/lib/src/exception/provider_already_booted_exception.dart b/packages/catalyst_builder_contracts/lib/src/exception/container_already_booted_exception.dart similarity index 55% rename from packages/catalyst_builder_contracts/lib/src/exception/provider_already_booted_exception.dart rename to packages/catalyst_builder_contracts/lib/src/exception/container_already_booted_exception.dart index 9a4d02a..8e1b20f 100644 --- a/packages/catalyst_builder_contracts/lib/src/exception/provider_already_booted_exception.dart +++ b/packages/catalyst_builder_contracts/lib/src/exception/container_already_booted_exception.dart @@ -2,9 +2,9 @@ import 'catalyst_builder_exception.dart'; /// An exception that is thrown when boot is called on a /// already booted ServiceProvider. -class ProviderAlreadyBootedException extends CatalystBuilderException { - /// Creates a new [ProviderAlreadyBootedException] object. - const ProviderAlreadyBootedException() +class ContainerAlreadyBootedException extends CatalystBuilderException { + /// Creates a new [ContainerAlreadyBootedException] object. + const ContainerAlreadyBootedException() : super( 'The service provider was already booted.', ); diff --git a/packages/catalyst_builder_contracts/lib/src/exception/exception.dart b/packages/catalyst_builder_contracts/lib/src/exception/exception.dart index bc5113e..3e846b2 100644 --- a/packages/catalyst_builder_contracts/lib/src/exception/exception.dart +++ b/packages/catalyst_builder_contracts/lib/src/exception/exception.dart @@ -1,5 +1,5 @@ export 'catalyst_builder_exception.dart'; export 'dependency_not_found_exception.dart'; -export 'provider_already_booted_exception.dart'; +export 'container_already_booted_exception.dart'; export 'container_not_booted_exception.dart'; export 'service_not_found_exception.dart'; diff --git a/packages/catalyst_builder_contracts/test/unit/exception/provider_already_booted_exception_test.dart b/packages/catalyst_builder_contracts/test/unit/exception/container_already_booted_exception_test.dart similarity index 84% rename from packages/catalyst_builder_contracts/test/unit/exception/provider_already_booted_exception_test.dart rename to packages/catalyst_builder_contracts/test/unit/exception/container_already_booted_exception_test.dart index fa533c5..5b250c6 100644 --- a/packages/catalyst_builder_contracts/test/unit/exception/provider_already_booted_exception_test.dart +++ b/packages/catalyst_builder_contracts/test/unit/exception/container_already_booted_exception_test.dart @@ -3,7 +3,7 @@ import 'package:test/test.dart'; void main() { test('constructor', () { - var ex = const ProviderAlreadyBootedException(); + var ex = const ContainerAlreadyBootedException(); expect(ex, const TypeMatcher()); expect(ex.message, equals('The service provider was already booted.')); }); From 892a5af4cb8c14f7239fd93994a403fdd19c1f1c Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Tue, 15 Apr 2025 06:32:02 +0200 Subject: [PATCH 4/9] change: Removed the catalyst_builder_container package --- .github/workflows/dart.yml | 24 -- README.md | 1 - .../lib/src/builder/constants.dart | 3 +- .../service_provider_plugin_builder.dart | 4 +- .../lib/src/catalyst_builder.dart | 1 + .../lib/src/service_container.dart | 0 .../catalyst_builder_container/.gitignore | 15 - .../catalyst_builder_container/CHANGELOG.md | 3 - packages/catalyst_builder_container/LICENSE | 21 - packages/catalyst_builder_container/README.md | 12 - .../analysis_options.yaml | 6 - .../example/.gitignore | 5 - .../example/bin/example.dart | 18 - .../example/lib/my_service.dart | 8 - .../example/pubspec.yaml | 25 -- .../lib/catalyst_builder_container.dart | 3 - .../catalyst_builder_container/pubspec.yaml | 27 -- .../test/service_container_test.dart | 366 ------------------ .../catalyst_builder_contracts/CHANGELOG.md | 5 - .../example/bin/example.dart | 1 - 20 files changed, 4 insertions(+), 544 deletions(-) create mode 100644 packages/catalyst_builder/lib/src/catalyst_builder.dart rename packages/{catalyst_builder_container => catalyst_builder}/lib/src/service_container.dart (100%) delete mode 100644 packages/catalyst_builder_container/.gitignore delete mode 100644 packages/catalyst_builder_container/CHANGELOG.md delete mode 100644 packages/catalyst_builder_container/LICENSE delete mode 100644 packages/catalyst_builder_container/README.md delete mode 100644 packages/catalyst_builder_container/analysis_options.yaml delete mode 100644 packages/catalyst_builder_container/example/.gitignore delete mode 100644 packages/catalyst_builder_container/example/bin/example.dart delete mode 100644 packages/catalyst_builder_container/example/lib/my_service.dart delete mode 100644 packages/catalyst_builder_container/example/pubspec.yaml delete mode 100644 packages/catalyst_builder_container/lib/catalyst_builder_container.dart delete mode 100644 packages/catalyst_builder_container/pubspec.yaml delete mode 100644 packages/catalyst_builder_container/test/service_container_test.dart diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 3fa3be2..0126c79 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -61,27 +61,3 @@ jobs: - name: Run tests run: dart test - test_catalyst_builder_container: - runs-on: ubuntu-latest - defaults: - run: - working-directory: packages/catalyst_builder_container - - steps: - - uses: actions/checkout@v2 - - - uses: dart-lang/setup-dart@v1 - with: - sdk: 'stable' - - - name: Install dependencies - run: dart pub get - - - name: Verify formatting - run: dart format --output=none --set-exit-if-changed lib - - - name: Analyze project source - run: dart analyze lib - - - name: Run tests - run: dart test diff --git a/README.md b/README.md index ad595ec..84b54fd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ This is the workspace root, select a specific package for more details. | Package | Description | Badges | |-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [`catalyst_builder`](./packages/catalyst_builder) | The builder package. Use this in your root package or plugin package to generate the ServiceContainerPlugin. | [![Pub](https://img.shields.io/pub/v/catalyst_builder.svg)](https://pub.dartlang.org/packages/catalyst_builder)
![Pub Points](https://img.shields.io/pub/points/catalyst_builder)
![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder)
![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder) | -| [`catalyst_builder_container`](./packages/catalyst_builder_container) | The container package. Use this package to resolve services from the container. | [![Pub](https://img.shields.io/pub/v/catalyst_builder_container.svg)](https://pub.dartlang.org/packages/catalyst_builder_container)
![Pub Points](https://img.shields.io/pub/points/catalyst_builder_container)
![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder_container)
![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder_container) | | [`catalyst_builder_contracts`](./packages/catalyst_builder_contracts) | The contracts package. Use this in packages that don't need to generate a service provider but provide services that can be resolved. | [![Pub](https://img.shields.io/pub/v/catalyst_builder_contracts.svg)](https://pub.dartlang.org/packages/catalyst_builder_contracts)
![Pub Points](https://img.shields.io/pub/points/catalyst_builder_contracts)
![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder_contracts)
![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder_contracts) | ## Roadmap diff --git a/packages/catalyst_builder/lib/src/builder/constants.dart b/packages/catalyst_builder/lib/src/builder/constants.dart index bc0713b..6a7fce4 100644 --- a/packages/catalyst_builder/lib/src/builder/constants.dart +++ b/packages/catalyst_builder/lib/src/builder/constants.dart @@ -1,6 +1,5 @@ const String preflightExtension = '.catalyst_builder.preflight.json'; -const String serviceProviderExtension = '.catalyst_builder.g.dart'; const String oldAnnotationsPrefix = 'package:catalyst_builder/src/annotation/'; -const String serviceProviderPluginExtension = '.catalyst_builder.plugin.g.dart'; +const String serviceContainerPluginExtension = '.catalyst_builder.plugin.g.dart'; const String annotationsPrefix = 'package:catalyst_builder_contracts/src/annotation/'; diff --git a/packages/catalyst_builder/lib/src/builder/service_provider_plugin_builder.dart b/packages/catalyst_builder/lib/src/builder/service_provider_plugin_builder.dart index ea6c698..333ae46 100644 --- a/packages/catalyst_builder/lib/src/builder/service_provider_plugin_builder.dart +++ b/packages/catalyst_builder/lib/src/builder/service_provider_plugin_builder.dart @@ -44,7 +44,7 @@ class ServiceProviderPluginBuilder implements Builder { var content = await _generateCode(buildStep, pluginClassName); await buildStep.writeAsString( - buildStep.inputId.changeExtension(serviceProviderPluginExtension), + buildStep.inputId.changeExtension(serviceContainerPluginExtension), content, ); } @@ -88,6 +88,6 @@ class ServiceProviderPluginBuilder implements Builder { @override Map> get buildExtensions => { r'$lib$': [], - r'.dart': [serviceProviderPluginExtension], + r'.dart': [serviceContainerPluginExtension], }; } diff --git a/packages/catalyst_builder/lib/src/catalyst_builder.dart b/packages/catalyst_builder/lib/src/catalyst_builder.dart new file mode 100644 index 0000000..516a235 --- /dev/null +++ b/packages/catalyst_builder/lib/src/catalyst_builder.dart @@ -0,0 +1 @@ +export 'service_container.dart'; \ No newline at end of file diff --git a/packages/catalyst_builder_container/lib/src/service_container.dart b/packages/catalyst_builder/lib/src/service_container.dart similarity index 100% rename from packages/catalyst_builder_container/lib/src/service_container.dart rename to packages/catalyst_builder/lib/src/service_container.dart diff --git a/packages/catalyst_builder_container/.gitignore b/packages/catalyst_builder_container/.gitignore deleted file mode 100644 index 15dd5e6..0000000 --- a/packages/catalyst_builder_container/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Files and directories created by pub. -.dart_tool/ -.packages -.idea/ - -# Conventional directory for build outputs. -build/ - -# Omit committing pubspec.lock for library packages; see -# https://dart.dev/guides/libraries/private-files#pubspeclock. -pubspec.lock -**/**.preflight.json -**/**.DS_Store - -**/*.g.dart \ No newline at end of file diff --git a/packages/catalyst_builder_container/CHANGELOG.md b/packages/catalyst_builder_container/CHANGELOG.md deleted file mode 100644 index a0edc74..0000000 --- a/packages/catalyst_builder_container/CHANGELOG.md +++ /dev/null @@ -1,3 +0,0 @@ -## 1.0.0-dev.1 - -First pre-release \ No newline at end of file diff --git a/packages/catalyst_builder_container/LICENSE b/packages/catalyst_builder_container/LICENSE deleted file mode 100644 index e7a9b1d..0000000 --- a/packages/catalyst_builder_container/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2025 Julian Finkler - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/packages/catalyst_builder_container/README.md b/packages/catalyst_builder_container/README.md deleted file mode 100644 index c9e350c..0000000 --- a/packages/catalyst_builder_container/README.md +++ /dev/null @@ -1,12 +0,0 @@ -[![GitHub license](https://img.shields.io/github/license/mintware-de/catalyst_builder)](https://github.com/mintware-de/catalyst_builder/blob/main/packages/catalyst_builder_container/LICENSE) -[![Pub](https://img.shields.io/pub/v/catalyst_builder_container.svg)](https://pub.dartlang.org/packages/catalyst_builder_container) -![Pub Points](https://img.shields.io/pub/points/catalyst_builder_container) -![Pub Publisher](https://img.shields.io/pub/publisher/catalyst_builder_container) -![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder_container) - -# Catalyst Builder Container - -This is the container package for [catalyst_builder](https://pub.dev/packages/catalyst_builder) - -For more details head over to the [wiki](https://github.com/mintware-de/catalyst_builder/wiki) - diff --git a/packages/catalyst_builder_container/analysis_options.yaml b/packages/catalyst_builder_container/analysis_options.yaml deleted file mode 100644 index 1498fff..0000000 --- a/packages/catalyst_builder_container/analysis_options.yaml +++ /dev/null @@ -1,6 +0,0 @@ -include: package:lints/recommended.yaml - -analyzer: - language: - strict-casts: true - strict-inference: true diff --git a/packages/catalyst_builder_container/example/.gitignore b/packages/catalyst_builder_container/example/.gitignore deleted file mode 100644 index b3bcdfa..0000000 --- a/packages/catalyst_builder_container/example/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# https://dart.dev/guides/libraries/private-files -# Created by `dart pub` -.dart_tool/ -.cache/ -**/*.g.dart diff --git a/packages/catalyst_builder_container/example/bin/example.dart b/packages/catalyst_builder_container/example/bin/example.dart deleted file mode 100644 index 682fdc9..0000000 --- a/packages/catalyst_builder_container/example/bin/example.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:catalyst_builder_container/catalyst_builder_container.dart'; -import 'package:catalyst_builder_contracts/catalyst_builder_contracts.dart'; -import 'package:catalyst_builder_contracts_example/my_service.dart'; - -import 'example.catalyst_builder.plugin.g.dart'; - -@GenerateServiceProviderPlugin( - // Enter a name that is used for the service provider class - pluginClassName: 'ExampleProviderPlugin', -) -void main() { - final provider = ServiceContainer(); - provider.useExampleProviderPlugin(); - provider.boot(); - - final service = provider.resolve(); - service.sayHello(); -} diff --git a/packages/catalyst_builder_container/example/lib/my_service.dart b/packages/catalyst_builder_container/example/lib/my_service.dart deleted file mode 100644 index 4b5ef21..0000000 --- a/packages/catalyst_builder_container/example/lib/my_service.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:catalyst_builder_contracts/catalyst_builder_contracts.dart'; - -@Service() -class MyService { - void sayHello() { - print('Hello World'); - } -} diff --git a/packages/catalyst_builder_container/example/pubspec.yaml b/packages/catalyst_builder_container/example/pubspec.yaml deleted file mode 100644 index ed70cb2..0000000 --- a/packages/catalyst_builder_container/example/pubspec.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: catalyst_builder_contracts_example -description: The example application for catalyst_builder_contracts -version: 1.0.0 - -publish_to: none - -environment: - sdk: ^3.6.1 - -# Add regular dependencies here. -dependencies: - catalyst_builder_contracts: - catalyst_builder_container: - -dev_dependencies: - build_runner: - catalyst_builder: - -dependency_overrides: - catalyst_builder_contracts: - path: ../../catalyst_builder_contracts - catalyst_builder: - path: ../../catalyst_builder - catalyst_builder_container: - path: ../ diff --git a/packages/catalyst_builder_container/lib/catalyst_builder_container.dart b/packages/catalyst_builder_container/lib/catalyst_builder_container.dart deleted file mode 100644 index 11608a5..0000000 --- a/packages/catalyst_builder_container/lib/catalyst_builder_container.dart +++ /dev/null @@ -1,3 +0,0 @@ -library; - -export 'src/service_container.dart'; diff --git a/packages/catalyst_builder_container/pubspec.yaml b/packages/catalyst_builder_container/pubspec.yaml deleted file mode 100644 index 5196b89..0000000 --- a/packages/catalyst_builder_container/pubspec.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: catalyst_builder_container -description: A lightweight and easy to use dependency injection container for dart. -version: 1.0.0-dev.1 -homepage: 'https://github.com/mintware-de/catalyst_builder' -repository: 'https://github.com/mintware-de/catalyst_builder/tree/main/packages/catalyst_builder' -documentation: 'https://github.com/mintware-de/catalyst_builder/wiki' -issue_tracker: 'https://github.com/mintware-de/catalyst_builder/issues?q=is:open%20label:catalyst_builder_container' -funding: - - https://github.com/sponsors/mintware-de - -topics: - - code-generation - - builder - - dependency-injection - - annotations - - service-provider - -environment: - sdk: ">=3.5.0 <4.0.0" - -dependencies: - analyzer: '>=6.2.0 <8.0.0' - catalyst_builder_contracts: ^2.0.0-dev.2 - -dev_dependencies: - test: any - lints: any \ No newline at end of file diff --git a/packages/catalyst_builder_container/test/service_container_test.dart b/packages/catalyst_builder_container/test/service_container_test.dart deleted file mode 100644 index 80b0ce8..0000000 --- a/packages/catalyst_builder_container/test/service_container_test.dart +++ /dev/null @@ -1,366 +0,0 @@ -import 'package:catalyst_builder_container/catalyst_builder_container.dart'; -import 'package:catalyst_builder_contracts/catalyst_builder_contracts.dart'; -import 'package:test/test.dart'; - -void main() { - late ServiceProvider serviceProvider; - - resetServiceProvider() { - serviceProvider = ServiceContainer(); - serviceProvider.applyPlugin(_TestPlugin()); - serviceProvider.parameters['paramOverride'] = 'XYZ'; - } - - setUp(() { - resetServiceProvider(); - serviceProvider.boot(); - }); - - test('try/Resolve should throw when the provider is not booted', () { - resetServiceProvider(); - expect( - () => serviceProvider.resolve(), - throwsA(const TypeMatcher()), - ); - }); - - test('double boot should throw an exception', () { - expect( - () => serviceProvider.boot(), - throwsA(const TypeMatcher()), - ); - }); - - test('tryResolve should not throw if a service was not found', () { - var result = serviceProvider.tryResolve(); - expect(result, isNull); - }); - - test('resolve should throw if a service was not found', () { - expect( - () => serviceProvider.resolve(), - throwsA(const TypeMatcher()), - ); - }); - - test('try/Resolve should inject parameters for non existing services', () { - expect(serviceProvider.resolve<_ServiceThatRequiresParameter>().parameter, - 'XYZ'); - expect( - serviceProvider.tryResolve<_ServiceThatRequiresParameter>()?.parameter, - 'XYZ'); - }); - - test('Services can be exposed as a specific type', () { - var provider = serviceProvider.resolve<_MarkerInterface>(); - expect(provider, const TypeMatcher<_ServiceThatRequiresParameter>()); - }); - - test('PreLoaded services should be loaded on boot', () { - expect(_PreloadService.shouldPreload, isFalse); - expect(_PreloadService.wasPreloaded, isFalse); - resetServiceProvider(); - _PreloadService.shouldPreload = true; - expect(_PreloadService.wasPreloaded, isFalse); - serviceProvider.boot(); - expect(_PreloadService.wasPreloaded, isTrue); - }); - - test('Singleton Service Lifetime', () { - var instance1 = serviceProvider.resolve<_MySingleton>(); - var instance2 = serviceProvider.resolve<_MySingleton>(); - - expect(instance1, same(instance2)); - }); - - test('Transient Service Lifetime', () { - var instance1 = serviceProvider.resolve<_MyTransient>(); - var instance2 = serviceProvider.resolve<_MyTransient>(); - - expect(instance1, isNot(same(instance2))); - }); - - test('hasService', () { - expect(serviceProvider.has<_MySingleton>(), isTrue); - expect(serviceProvider.has(), isFalse); - }); - - test('service registration', () { - if (serviceProvider is! ServiceRegistry) { - fail('Service provider is not a ServiceRegistry'); - } - expect(serviceProvider.has<_SelfRegisteredService>(), isFalse); - (serviceProvider as ServiceRegistry).register( - (provider) => _MySelfRegisteredService(provider.resolve()), - const Service(exposeAs: _SelfRegisteredService), - ); - expect(serviceProvider.has<_SelfRegisteredService>(), isTrue); - }); - - test('enhance', () { - expect(serviceProvider.has<_SelfRegisteredService>(), isFalse); - - var newProvider = serviceProvider.enhance(services: [ - LazyServiceDescriptor( - (p) => _MySelfRegisteredService(), - const Service(exposeAs: _SelfRegisteredService), - ) - ]); - - expect(newProvider.has<_SelfRegisteredService>(), isTrue); - expect(serviceProvider.has<_SelfRegisteredService>(), isFalse); - - var mySvc = newProvider.resolve<_SelfRegisteredService>(); - expect(mySvc.foo, equals('bar')); - }); - test('enhance with parameter', () { - serviceProvider.parameters['foo'] = 'bar'; - serviceProvider.parameters['bar'] = 'baz'; - expect(serviceProvider.has<_SelfRegisteredService>(), isFalse); - - var newProvider = serviceProvider.enhance( - parameters: { - 'foo': 'overwritten', - }, - services: [ - LazyServiceDescriptor( - (p) => _MySelfRegisteredService(p.parameters['foo'] as String), - const Service(exposeAs: _SelfRegisteredService), - ), - ], - ); - - var mySvc = newProvider.resolve<_SelfRegisteredService>(); - expect(mySvc.foo, equals('overwritten')); - expect(newProvider.parameters.containsKey('bar'), isTrue); - }); - test('enhance with multiple descriptors', () { - expect(serviceProvider.has<_SelfRegisteredService>(), isFalse); - expect(serviceProvider.has(), isFalse); - - var newProvider = serviceProvider.enhance( - services: [ - LazyServiceDescriptor<_MySelfRegisteredService>( - (p) => _MySelfRegisteredService(p.resolve()), - const Service(exposeAs: _SelfRegisteredService), - ), - LazyServiceDescriptor( - (p) => 'This should also work', - const Service(exposeAs: String), - ), - ], - ); - - expect(newProvider.has(), isFalse); - expect(newProvider.has<_SelfRegisteredService>(), isTrue); - expect(newProvider.has(), isTrue); - expect(newProvider.resolve<_SelfRegisteredService>(), isNotNull); - expect(newProvider.resolve(), 'This should also work'); - }); - - test('enhance should contain previous manual registered services', () { - expect(serviceProvider.has<_SelfRegisteredService>(), isFalse); - expect(serviceProvider.has(), isFalse); - - var newProvider = serviceProvider.enhance( - services: [ - LazyServiceDescriptor<_MySelfRegisteredService>( - (p) => _MySelfRegisteredService(p.resolve()), - const Service(exposeAs: _SelfRegisteredService), - ), - ], - ); - - expect(newProvider.has<_SelfRegisteredService>(), isTrue); - expect(newProvider.has(), isFalse); - - var newProvider2 = newProvider.enhance( - services: [ - LazyServiceDescriptor( - (p) => 'This should also work', - const Service(exposeAs: String), - ), - ], - ); - - expect(newProvider2.has<_SelfRegisteredService>(), isTrue); - expect(newProvider2.has(), isTrue); - }); - - test('resolveByTag', () { - var services = serviceProvider.resolveByTag(#tagToInject); - expect(services, isNotEmpty); - }); - - test('inject tagged services', () { - var service = serviceProvider.resolve<_ServiceWithTaggedDependencies>(); - expect(service.dependencies.length, equals(2)); - }); - - test('enhance should not override default descriptors', () { - expect(serviceProvider.has<_ServiceThatDependOnEnhancedService>(), isTrue); - expect( - () => serviceProvider.resolve<_ServiceThatDependOnEnhancedService>(), - throwsA(const TypeMatcher()), - ); - - var enhanced = serviceProvider.enhance( - services: [ - LazyServiceDescriptor<_ServiceOnlyProvidedInEnhanced>( - (p) => _ServiceOnlyProvidedInEnhanced(), - const Service(exposeAs: _ServiceOnlyProvidedInEnhanced), - ) - ], - ); - - expect(enhanced.has<_ServiceThatDependOnEnhancedService>(), isTrue); - expect( - enhanced.resolve<_ServiceThatDependOnEnhancedService>().dependency.foo, - equals('bar')); - }); - - test('enhance should register singletons in the root provider', () { - var enhanced1 = serviceProvider.enhance(); - expect(enhanced1.resolve<_SingletonThatShouldBeRegisteredInRoot>().count, - equals(1)); - - var enhanced2 = serviceProvider.enhance(); - expect(enhanced2.resolve<_SingletonThatShouldBeRegisteredInRoot>().count, - equals(1)); - }); -} - -// Testing services - -abstract interface class _MarkerInterface { - String get parameter; -} - -class _ServiceThatRequiresParameter implements _MarkerInterface { - @override - final String parameter; - - _ServiceThatRequiresParameter( - @Inject(parameter: 'paramOverride') this.parameter); -} - -class _MySingleton {} - -class _MyTransient {} - -class _SingletonThatShouldBeRegisteredInRoot { - static var _count = 0; - - int get count => _count; - - _SingletonThatShouldBeRegisteredInRoot() { - _count++; - } -} - -class _ServiceOnlyProvidedInEnhanced { - String get foo => 'bar'; -} - -class _ServiceThatDependOnEnhancedService { - final _ServiceOnlyProvidedInEnhanced dependency; - - _ServiceThatDependOnEnhancedService(this.dependency); -} - -abstract class _SelfRegisteredService { - String get foo; - - void sayHello(); -} - -class _MySelfRegisteredService implements _SelfRegisteredService { - @override - final String foo; - - _MySelfRegisteredService([this.foo = 'bar']); - - @override - void sayHello() {} -} - -class _ServiceWithTaggedDependencies { - final List dependencies; - - _ServiceWithTaggedDependencies(@Inject(tag: #tagToInject) this.dependencies); -} - -class _PreloadService { - static bool shouldPreload = false; - static bool wasPreloaded = false; - - _PreloadService() { - if (shouldPreload) { - wasPreloaded = true; - } - } -} - -class _TestPlugin implements ServiceProviderPlugin { - @override - Map provideExposes() { - return {}; - } - - @override - Map provideKnownServices(ServiceProvider p) { - return { - _ServiceThatRequiresParameter: - ServiceDescriptor<_ServiceThatRequiresParameter>( - Service(), - () => _ServiceThatRequiresParameter(p.resolveOrGetParameter( - _ServiceThatRequiresParameter, 'parameter', 'paramOverride')), - ), - _MarkerInterface: ServiceDescriptor<_ServiceThatRequiresParameter>( - Service(exposeAs: _MarkerInterface), - () => _ServiceThatRequiresParameter(p.resolveOrGetParameter( - _ServiceThatRequiresParameter, 'parameter', 'paramOverride')), - ), - _MySingleton: ServiceDescriptor<_MySingleton>( - Service(lifetime: ServiceLifetime.singleton), - () => _MySingleton(), - ), - _MyTransient: ServiceDescriptor<_MyTransient>( - Service(lifetime: ServiceLifetime.transient), - () => _MyTransient(), - ), - _ServiceWithTaggedDependencies: - ServiceDescriptor<_ServiceWithTaggedDependencies>( - Service(lifetime: ServiceLifetime.singleton), - () => _ServiceWithTaggedDependencies( - p.resolveByTag(#tagToInject).cast())), - _SingletonThatShouldBeRegisteredInRoot: - ServiceDescriptor<_SingletonThatShouldBeRegisteredInRoot>( - Service(lifetime: ServiceLifetime.singleton), - () => _SingletonThatShouldBeRegisteredInRoot(), - ), - _ServiceThatDependOnEnhancedService: - ServiceDescriptor<_ServiceThatDependOnEnhancedService>( - Service(lifetime: ServiceLifetime.singleton), - () => _ServiceThatDependOnEnhancedService(p.resolveOrGetParameter( - _ServiceThatDependOnEnhancedService, 'dependency')), - ), - _PreloadService: ServiceDescriptor<_PreloadService>( - Service(), - () => _PreloadService(), - ) - }; - } - - @override - List providePreloadedTypes() { - return [_PreloadService]; - } - - @override - Map> provideServiceTags() { - return { - #tagToInject: [_MySingleton, _MyTransient], - }; - } -} diff --git a/packages/catalyst_builder_contracts/CHANGELOG.md b/packages/catalyst_builder_contracts/CHANGELOG.md index c4c0290..5d12c05 100644 --- a/packages/catalyst_builder_contracts/CHANGELOG.md +++ b/packages/catalyst_builder_contracts/CHANGELOG.md @@ -1,8 +1,3 @@ -## Next - -### Breaking Changes -- Removed `GenerateServiceProvider`. Use `ServiceContainer` from the `catalyst_builder_container` package. - ## 2.0.0-dev.2 ### Breaking Changes diff --git a/packages/catalyst_builder_contracts/example/bin/example.dart b/packages/catalyst_builder_contracts/example/bin/example.dart index 682fdc9..928951e 100644 --- a/packages/catalyst_builder_contracts/example/bin/example.dart +++ b/packages/catalyst_builder_contracts/example/bin/example.dart @@ -1,4 +1,3 @@ -import 'package:catalyst_builder_container/catalyst_builder_container.dart'; import 'package:catalyst_builder_contracts/catalyst_builder_contracts.dart'; import 'package:catalyst_builder_contracts_example/my_service.dart'; From c232dea7143a2d2966f42f17b9a931642c88d551 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Tue, 15 Apr 2025 07:03:26 +0200 Subject: [PATCH 5/9] change: Rename provider to container --- README.md | 12 ++++----- packages/catalyst_builder/README.md | 6 ++--- packages/catalyst_builder/build.yaml | 10 +++----- .../example/bin/catalyst_builder_example.dart | 22 ++++++++-------- .../catalyst_builder/example/lib/example.dart | 4 +-- .../catalyst_builder/example/pubspec.yaml | 8 ++---- .../lib/catalyst_builder.dart | 1 + .../lib/src/builder/builders.dart | 8 +++--- .../methods/methods.dart | 0 .../methods/provide_exposes.dart | 0 .../methods/provide_known_services.dart | 8 +++--- .../methods/provide_preloaded_types.dart | 0 .../methods/provide_service_tags.dart | 0 .../service_container_plugin.dart} | 8 +++--- .../service_factory/service_factory.dart | 10 ++++---- .../lib/src/builder/generator/symbols.dart | 25 ++++++++++++------- ... => service_container_plugin_builder.dart} | 12 ++++----- .../lib/src/catalyst_builder.dart | 1 - .../lib/src/service_container.dart | 8 +++--- packages/catalyst_builder/pubspec.yaml | 7 +++++- .../lib/third_party_dependency.dart | 2 +- .../example/bin/example.dart | 15 +++++------ .../example/pubspec.yaml | 4 +-- .../lib/catalyst_builder_contracts.dart | 4 +-- ...r.dart => abstract_service_container.dart} | 18 ++++++------- .../lib/src/annotation/annotation.dart | 2 +- ...=> generate_service_container_plugin.dart} | 6 ++--- .../lib/src/annotation/inject.dart | 12 +++------ .../lib/src/annotation/preload.dart | 4 +-- .../lib/src/annotation/service.dart | 7 +++--- .../container_already_booted_exception.dart | 4 +-- .../container_not_booted_exception.dart | 2 +- ...gin.dart => service_container_plugin.dart} | 6 ++--- .../lib/src/service_descriptor.dart | 2 +- .../lib/src/service_lifetime.dart | 2 +- .../lib/src/service_registry.dart | 6 ++--- ...ntainer_already_booted_exception_test.dart | 2 +- .../container_not_booted_exception_test.dart | 2 +- 38 files changed, 124 insertions(+), 126 deletions(-) create mode 100644 packages/catalyst_builder/lib/catalyst_builder.dart rename packages/catalyst_builder/lib/src/builder/generator/{service_provider => service_container}/methods/methods.dart (100%) rename packages/catalyst_builder/lib/src/builder/generator/{service_provider => service_container}/methods/provide_exposes.dart (100%) rename packages/catalyst_builder/lib/src/builder/generator/{service_provider => service_container}/methods/provide_known_services.dart (89%) rename packages/catalyst_builder/lib/src/builder/generator/{service_provider => service_container}/methods/provide_preloaded_types.dart (100%) rename packages/catalyst_builder/lib/src/builder/generator/{service_provider => service_container}/methods/provide_service_tags.dart (100%) rename packages/catalyst_builder/lib/src/builder/generator/{service_provider/service_provider_plugin.dart => service_container/service_container_plugin.dart} (81%) rename packages/catalyst_builder/lib/src/builder/{service_provider_plugin_builder.dart => service_container_plugin_builder.dart} (85%) delete mode 100644 packages/catalyst_builder/lib/src/catalyst_builder.dart rename packages/catalyst_builder_contracts/lib/src/{service_provider.dart => abstract_service_container.dart} (72%) rename packages/catalyst_builder_contracts/lib/src/annotation/{generate_service_provider_plugin.dart => generate_service_container_plugin.dart} (70%) rename packages/catalyst_builder_contracts/lib/src/{service_provider_plugin.dart => service_container_plugin.dart} (68%) diff --git a/README.md b/README.md index 84b54fd..31f0747 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ # Catalyst Builder -A dependency injection provider builder for dart. +A dependency injection container builder for dart. This is the workspace root, select a specific package for more details. -| Package | Description | Badges | -|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [`catalyst_builder`](./packages/catalyst_builder) | The builder package. Use this in your root package or plugin package to generate the ServiceContainerPlugin. | [![Pub](https://img.shields.io/pub/v/catalyst_builder.svg)](https://pub.dartlang.org/packages/catalyst_builder)
![Pub Points](https://img.shields.io/pub/points/catalyst_builder)
![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder)
![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder) | -| [`catalyst_builder_contracts`](./packages/catalyst_builder_contracts) | The contracts package. Use this in packages that don't need to generate a service provider but provide services that can be resolved. | [![Pub](https://img.shields.io/pub/v/catalyst_builder_contracts.svg)](https://pub.dartlang.org/packages/catalyst_builder_contracts)
![Pub Points](https://img.shields.io/pub/points/catalyst_builder_contracts)
![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder_contracts)
![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder_contracts) | +| Package | Description | Badges | +|-----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`catalyst_builder`](./packages/catalyst_builder) | The builder package. Use this in your root package or plugin package to generate the ServiceContainerPlugin. | [![Pub](https://img.shields.io/pub/v/catalyst_builder.svg)](https://pub.dartlang.org/packages/catalyst_builder)
![Pub Points](https://img.shields.io/pub/points/catalyst_builder)
![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder)
![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder) | +| [`catalyst_builder_contracts`](./packages/catalyst_builder_contracts) | The contracts package. Use this in packages that don't need to generate a service container but provide services that can be resolved. | [![Pub](https://img.shields.io/pub/v/catalyst_builder_contracts.svg)](https://pub.dartlang.org/packages/catalyst_builder_contracts)
![Pub Points](https://img.shields.io/pub/points/catalyst_builder_contracts)
![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder_contracts)
![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder_contracts) | ## Roadmap @@ -19,6 +19,6 @@ This is the workspace root, select a specific package for more details. | Description | Status | |---------------------------------------------------------------------------|--------| | Remove the annotations inside the catalyst_builder_package | ☑️ | -| Remove the service provider subclasses | ☑️ | +| Remove the service container subclasses | ☑️ | | Stop generating the ServiceProvider and create a default ServiceContainer | ☑️ | | Add scope support | 🔲 | diff --git a/packages/catalyst_builder/README.md b/packages/catalyst_builder/README.md index ec984df..364bc14 100644 --- a/packages/catalyst_builder/README.md +++ b/packages/catalyst_builder/README.md @@ -8,7 +8,7 @@ # Catalyst Builder -A dependency injection provider builder for dart. +A dependency injection container builder for dart. Click on the image for a video on YouTube: @@ -24,9 +24,9 @@ Since [Catalyst](https://github.com/mintware-de/catalyst) is only for Dart and [Flutter Catalyst](https://github.com/mintware-de/flutter_catalyst) supports Flutter, but a mess to configure I decided to do something cooler. -Catalyst Builder is a dependency injection provider builder for both, Dart and Flutter. It's easy to use and dependency +Catalyst Builder is a dependency injection container builder for both, Dart and Flutter. It's easy to use and dependency injection is almost done automatically. You only have to decorate your services with `@Service` and the build_runner -will create a service provider for you. +will create a service container for you. ## Installation diff --git a/packages/catalyst_builder/build.yaml b/packages/catalyst_builder/build.yaml index d6eb15a..733bace 100644 --- a/packages/catalyst_builder/build.yaml +++ b/packages/catalyst_builder/build.yaml @@ -8,16 +8,14 @@ builders: build_to: cache auto_apply: root_package runs_before: - - 'catalyst_builder:buildServiceProvider' - - 'catalyst_builder:buildServiceProviderPlugin' + - 'catalyst_builder:buildServiceContainerPlugin' applies_builders: - - 'catalyst_builder:buildServiceProvider' - - 'catalyst_builder:buildServiceProviderPlugin' + - 'catalyst_builder:buildServiceContainerPlugin' - buildServiceProviderPlugin: + buildServiceContainerPlugin: import: 'package:catalyst_builder/src/builder/builders.dart' builder_factories: - - 'createServiceProviderPluginBuilder' + - 'createServiceContainerPluginBuilder' build_extensions: { '.dart': [ '.catalyst_builder.plugin.g.dart' ] } build_to: source auto_apply: dependents diff --git a/packages/catalyst_builder/example/bin/catalyst_builder_example.dart b/packages/catalyst_builder/example/bin/catalyst_builder_example.dart index a830c27..4e03ea5 100644 --- a/packages/catalyst_builder/example/bin/catalyst_builder_example.dart +++ b/packages/catalyst_builder/example/bin/catalyst_builder_example.dart @@ -1,33 +1,33 @@ -import 'package:catalyst_builder_container/catalyst_builder_container.dart'; +import 'package:catalyst_builder/catalyst_builder.dart'; import 'package:catalyst_builder_example/example.dart'; void main(List arguments) { - var provider = ServiceContainer(); - provider.useExampleProviderPlugin(); + var container = ServiceContainer(); + container.useExampleContainerPlugin(); - provider.parameters['sender_username'] = 'Julian'; + container.parameters['sender_username'] = 'Julian'; print('Post parameter set, pre boot'); - provider.boot(); + container.boot(); print('Post boot, pre resolve'); - var chat = provider.resolve(); + var chat = container.resolve(); print(chat.runtimeType); chat.sendChatMessage('WTF, this is really cool!'); - provider.register( - (provider) => MySelfRegisteredService(provider.resolve()), + container.register( + (container) => MySelfRegisteredService(container.resolve()), ); - var selfRegistered = provider.resolve(); + var selfRegistered = container.resolve(); selfRegistered.sayHello(); // Contains CoolChatProvider and ConsoleTransport - var servicesByTag = provider.resolveByTag(#chat); + var servicesByTag = container.resolveByTag(#chat); for (var svc in servicesByTag) { print(svc); } - var broadcaster = provider.resolve(); + var broadcaster = container.resolve(); broadcaster.sendChatMessage('Hello Broadcast using injection tag.'); } diff --git a/packages/catalyst_builder/example/lib/example.dart b/packages/catalyst_builder/example/lib/example.dart index 8fa768c..c3b0177 100644 --- a/packages/catalyst_builder/example/lib/example.dart +++ b/packages/catalyst_builder/example/lib/example.dart @@ -7,8 +7,8 @@ export './src/manually_wired_service.dart'; export 'example.catalyst_builder.plugin.g.dart'; @Preload() -@GenerateServiceProviderPlugin( - pluginClassName: 'ExampleProviderPlugin', +@GenerateServiceContainerPlugin( + pluginClassName: 'ExampleContainerPlugin', ) @ServiceMap(services: { ManuallyWiredServiceImplementation: Service( diff --git a/packages/catalyst_builder/example/pubspec.yaml b/packages/catalyst_builder/example/pubspec.yaml index d7b3eb4..97034aa 100644 --- a/packages/catalyst_builder/example/pubspec.yaml +++ b/packages/catalyst_builder/example/pubspec.yaml @@ -12,19 +12,15 @@ dependencies: path: ../../catalyst_builder_contracts third_party_dependency: path: ../test/third_party_dependency - catalyst_builder_container: - path: ../../catalyst_builder_container + catalyst_builder: + path: ../ dev_dependencies: lints: ^5.1.1 build_runner: ^2.0.1 - catalyst_builder: - path: ../ dependency_overrides: catalyst_builder: path: ../ catalyst_builder_contracts: path: ../../catalyst_builder_contracts - catalyst_builder_container: - path: ../../catalyst_builder_container \ No newline at end of file diff --git a/packages/catalyst_builder/lib/catalyst_builder.dart b/packages/catalyst_builder/lib/catalyst_builder.dart new file mode 100644 index 0000000..60a5f07 --- /dev/null +++ b/packages/catalyst_builder/lib/catalyst_builder.dart @@ -0,0 +1 @@ +export 'src/service_container.dart'; \ No newline at end of file diff --git a/packages/catalyst_builder/lib/src/builder/builders.dart b/packages/catalyst_builder/lib/src/builder/builders.dart index 8f8e3b1..fcb5f36 100644 --- a/packages/catalyst_builder/lib/src/builder/builders.dart +++ b/packages/catalyst_builder/lib/src/builder/builders.dart @@ -1,11 +1,11 @@ import 'package:build/build.dart'; import 'preflight_builder.dart'; -import 'service_provider_plugin_builder.dart'; +import 'service_container_plugin_builder.dart'; /// Creates the builder for the preflight step Builder createPreflightBuilder(BuilderOptions options) => PreflightBuilder(); -/// Creates the service provider plugin builder -Builder createServiceProviderPluginBuilder(BuilderOptions options) => - ServiceProviderPluginBuilder(); +/// Creates the service container plugin builder +Builder createServiceContainerPluginBuilder(BuilderOptions options) => + ServiceContainerPluginBuilder(); diff --git a/packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/methods.dart b/packages/catalyst_builder/lib/src/builder/generator/service_container/methods/methods.dart similarity index 100% rename from packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/methods.dart rename to packages/catalyst_builder/lib/src/builder/generator/service_container/methods/methods.dart diff --git a/packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_exposes.dart b/packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_exposes.dart similarity index 100% rename from packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_exposes.dart rename to packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_exposes.dart diff --git a/packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_known_services.dart b/packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_known_services.dart similarity index 89% rename from packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_known_services.dart rename to packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_known_services.dart index edc8085..c174863 100644 --- a/packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_known_services.dart +++ b/packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_known_services.dart @@ -8,7 +8,7 @@ import '../../symbols.dart'; cb.Method provideKnownServicesTemplate(List services) { var serviceFactories = {}; - var pP = cb.refer('p'); + var containerP = cb.refer('c'); for (var svc in services) { var serviceType = cb.refer(svc.service.symbolName, svc.service.library); @@ -22,7 +22,7 @@ cb.Method provideKnownServicesTemplate(List services) { exposeAsReference, serviceType, svc, - pP, + containerP, ); } @@ -32,8 +32,8 @@ cb.Method provideKnownServicesTemplate(List services) { ..name = provideKnownServices$.symbol ..returns = mapOfT(typeT, serviceDescriptorT) ..requiredParameters.add(cb.Parameter((p) => p - ..name = pP.symbol! - ..type = serviceProviderT)) + ..name = containerP.symbol! + ..type = abstractServiceContainerT)) ..body = cb .literalMap(serviceFactories, typeT, serviceDescriptorT) .returned diff --git a/packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_preloaded_types.dart b/packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_preloaded_types.dart similarity index 100% rename from packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_preloaded_types.dart rename to packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_preloaded_types.dart diff --git a/packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_service_tags.dart b/packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_service_tags.dart similarity index 100% rename from packages/catalyst_builder/lib/src/builder/generator/service_provider/methods/provide_service_tags.dart rename to packages/catalyst_builder/lib/src/builder/generator/service_container/methods/provide_service_tags.dart diff --git a/packages/catalyst_builder/lib/src/builder/generator/service_provider/service_provider_plugin.dart b/packages/catalyst_builder/lib/src/builder/generator/service_container/service_container_plugin.dart similarity index 81% rename from packages/catalyst_builder/lib/src/builder/generator/service_provider/service_provider_plugin.dart rename to packages/catalyst_builder/lib/src/builder/generator/service_container/service_container_plugin.dart index 79f42ec..d06a128 100644 --- a/packages/catalyst_builder/lib/src/builder/generator/service_provider/service_provider_plugin.dart +++ b/packages/catalyst_builder/lib/src/builder/generator/service_container/service_container_plugin.dart @@ -4,14 +4,14 @@ import '../../dto/dto.dart'; import '../symbols.dart'; import 'methods/methods.dart'; -/// Generates the code for the service provider. -cb.Class buildServiceProviderPluginClass( +/// Generates the code for the service container. +cb.Class buildServiceContainerPluginClass( String pluginClassName, List services, ) { return cb.Class((c) => c ..name = pluginClassName - ..implements.addAll([serviceProviderPluginT]) + ..implements.addAll([serviceContainerPluginT]) ..methods.addAll([ provideKnownServicesTemplate(services), provideExposesTemplate(services), @@ -23,7 +23,7 @@ cb.Class buildServiceProviderPluginClass( cb.Extension buildExtension(String pluginClassName) { return cb.Extension((e) => e ..name = "${pluginClassName}Extension" - ..on = serviceProviderT + ..on = abstractServiceContainerT ..methods.add(cb.Method((m) => m ..name = "use$pluginClassName" ..returns = voidT diff --git a/packages/catalyst_builder/lib/src/builder/generator/service_factory/service_factory.dart b/packages/catalyst_builder/lib/src/builder/generator/service_factory/service_factory.dart index 8cb5ba8..486ff6a 100644 --- a/packages/catalyst_builder/lib/src/builder/generator/service_factory/service_factory.dart +++ b/packages/catalyst_builder/lib/src/builder/generator/service_factory/service_factory.dart @@ -10,7 +10,7 @@ cb.Expression buildServiceFactory( cb.Reference? exposeAsReference, cb.Reference serviceType, ExtractedService svc, - cb.Reference providerP, + cb.Reference containerP, ) { var factory = cb.MethodBuilder(); @@ -21,10 +21,10 @@ cb.Expression buildServiceFactory( var namedArgs = {}; var tryResolveOrGetParameter_ = - providerP.property(tryResolveOrGetParameter$.symbol!); - var resolveByTag_ = providerP.property(resolveByTag$.symbol!); + containerP.property(tryResolveOrGetParameter$.symbol!); + var resolveByTag_ = containerP.property(resolveByTag$.symbol!); var resolveOrGetParameter_ = - providerP.property(resolveOrGetParameter$.symbol!); + containerP.property(resolveOrGetParameter$.symbol!); for (var param in svc.constructorArgs) { var defaultValue = ''; @@ -61,7 +61,7 @@ cb.Expression buildServiceFactory( return serviceDescriptorT.call([ serviceT.constInstance([], { if (svc.lifetime != ServiceLifetime.singleton.toString()) - 'lifetime': cb.refer(svc.lifetime, rootPackage), + 'lifetime': cb.refer(svc.lifetime, contractsPackage), if (exposeAsReference != null) 'exposeAs': exposeAsReference }), constructor, diff --git a/packages/catalyst_builder/lib/src/builder/generator/symbols.dart b/packages/catalyst_builder/lib/src/builder/generator/symbols.dart index f69f88f..4967681 100644 --- a/packages/catalyst_builder/lib/src/builder/generator/symbols.dart +++ b/packages/catalyst_builder/lib/src/builder/generator/symbols.dart @@ -1,19 +1,25 @@ import 'package:code_builder/code_builder.dart' as cb; /// The catalyst_builder root package. -const rootPackage = +const contractsPackage = 'package:catalyst_builder_contracts/catalyst_builder_contracts.dart'; +const builderPackage = 'package:catalyst_builder/catalyst_builder.dart'; + /// [Service] -final serviceT = cb.refer('Service', rootPackage); +final serviceT = cb.refer('Service', contractsPackage); /// [ServiceDescriptor] -final serviceDescriptorT = cb.refer('ServiceDescriptor', rootPackage); +final serviceDescriptorT = cb.refer('ServiceDescriptor', contractsPackage); + +/// [ServiceContainer] +final serviceContainerT = cb.refer('ServiceContainer', builderPackage); -/// [ServiceProvider] -final serviceProviderT = cb.refer('ServiceProvider', rootPackage); +/// [AbstractServiceContainer] +final abstractServiceContainerT = + cb.refer('AbstractServiceContainer', contractsPackage); -/// [ServiceProvider.resolveByTag] +/// [ServiceContainer.resolveByTag] final resolveByTag$ = cb.refer('resolveByTag'); /// tryResolveOrGetParameter method @@ -42,11 +48,12 @@ cb.Reference mapOfT(cb.Reference tKey, cb.Reference tValue) => ..types.addAll([tKey, tValue])) .build(); -/// [ServiceProvider.applyPlugin] method +/// [ServiceContainer.applyPlugin] method final applyPlugin$ = cb.refer('applyPlugin'); -/// [ServiceProviderPlugin] -final serviceProviderPluginT = cb.refer('ServiceProviderPlugin', rootPackage); +/// [ServiceContainerPlugin] +final serviceContainerPluginT = + cb.refer('ServiceContainerPlugin', contractsPackage); /// provideKnownServices method final provideKnownServices$ = cb.refer('provideKnownServices'); diff --git a/packages/catalyst_builder/lib/src/builder/service_provider_plugin_builder.dart b/packages/catalyst_builder/lib/src/builder/service_container_plugin_builder.dart similarity index 85% rename from packages/catalyst_builder/lib/src/builder/service_provider_plugin_builder.dart rename to packages/catalyst_builder/lib/src/builder/service_container_plugin_builder.dart index 333ae46..da96f4e 100644 --- a/packages/catalyst_builder/lib/src/builder/service_provider_plugin_builder.dart +++ b/packages/catalyst_builder/lib/src/builder/service_container_plugin_builder.dart @@ -3,18 +3,18 @@ import 'dart:convert'; import 'package:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; -import 'package:catalyst_builder/src/builder/generator/service_provider/service_provider_plugin.dart'; -import 'package:catalyst_builder/src/builder/helpers.dart'; import 'package:code_builder/code_builder.dart'; import 'package:dart_style/dart_style.dart'; import 'package:glob/glob.dart'; import 'constants.dart'; import 'dto/dto.dart'; +import 'generator/service_container/service_container_plugin.dart'; +import 'helpers.dart'; -/// The ServiceProviderPluginBuilder creates a plugin from the resulting +/// The ServiceContainerPluginBuilder creates a plugin from the resulting /// preflight .json files. -class ServiceProviderPluginBuilder implements Builder { +class ServiceContainerPluginBuilder implements Builder { @override FutureOr build(BuildStep buildStep) async { if (!await buildStep.resolver.isLibrary(buildStep.inputId)) { @@ -30,7 +30,7 @@ class ServiceProviderPluginBuilder implements Builder { var annotation = libraryElement.topLevelElements .map((el) => el.metadata.where( - (m) => m.isLibraryAnnotation('GenerateServiceProviderPlugin'))) + (m) => m.isLibraryAnnotation('GenerateServiceContainerPlugin'))) .fold([], (prev, e) => [...prev, ...e]).firstOrNull; var isEntryPoint = annotation != null; @@ -71,7 +71,7 @@ class ServiceProviderPluginBuilder implements Builder { final rawOutput = Library( (l) => l.body.addAll([ - buildServiceProviderPluginClass(pluginClassName, services), + buildServiceContainerPluginClass(pluginClassName, services), buildExtension(pluginClassName), ]), ).accept(emitter).toString(); diff --git a/packages/catalyst_builder/lib/src/catalyst_builder.dart b/packages/catalyst_builder/lib/src/catalyst_builder.dart deleted file mode 100644 index 516a235..0000000 --- a/packages/catalyst_builder/lib/src/catalyst_builder.dart +++ /dev/null @@ -1 +0,0 @@ -export 'service_container.dart'; \ No newline at end of file diff --git a/packages/catalyst_builder/lib/src/service_container.dart b/packages/catalyst_builder/lib/src/service_container.dart index ec262e2..b46da05 100644 --- a/packages/catalyst_builder/lib/src/service_container.dart +++ b/packages/catalyst_builder/lib/src/service_container.dart @@ -2,7 +2,7 @@ import 'package:catalyst_builder_contracts/catalyst_builder_contracts.dart'; /// This is a service container. Use it to register and resolve services /// from your app. -class ServiceContainer implements ServiceProvider, ServiceRegistry { +class ServiceContainer implements AbstractServiceContainer, ServiceRegistry { @override final parameters = {}; @@ -14,7 +14,7 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry { final _preloadedTypes = []; - final _appliedPlugins = []; + final _appliedPlugins = []; var _serviceInstances = {}; @@ -137,7 +137,7 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry { } @override - ServiceProvider enhance({ + AbstractServiceContainer enhance({ List services = const [], Map parameters = const {}, }) { @@ -167,7 +167,7 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry { } @override - void applyPlugin(ServiceProviderPlugin plugin) { + void applyPlugin(ServiceContainerPlugin plugin) { if (_booted) { throw const ContainerAlreadyBootedException(); } diff --git a/packages/catalyst_builder/pubspec.yaml b/packages/catalyst_builder/pubspec.yaml index 419e70c..abcb3c1 100644 --- a/packages/catalyst_builder/pubspec.yaml +++ b/packages/catalyst_builder/pubspec.yaml @@ -1,5 +1,5 @@ name: catalyst_builder -description: A lightweight and easy to use dependency injection provider builder for dart. +description: A lightweight and easy to use dependency injection container builder for dart. version: 5.0.0-dev.2 homepage: 'https://github.com/mintware-de/catalyst_builder' repository: 'https://github.com/mintware-de/catalyst_builder/tree/main/packages/catalyst_builder' @@ -40,3 +40,8 @@ dev_dependencies: test: any lints: any build_runner: ^2.2.0 + + +dependency_overrides: + catalyst_builder_contracts: + path: ../catalyst_builder_contracts \ No newline at end of file diff --git a/packages/catalyst_builder/test/third_party_dependency/lib/third_party_dependency.dart b/packages/catalyst_builder/test/third_party_dependency/lib/third_party_dependency.dart index 9c94986..853c146 100644 --- a/packages/catalyst_builder/test/third_party_dependency/lib/third_party_dependency.dart +++ b/packages/catalyst_builder/test/third_party_dependency/lib/third_party_dependency.dart @@ -27,7 +27,7 @@ class SingletonThatShouldBeRegisteredInRoot { } } -@GenerateServiceProviderPlugin( +@GenerateServiceContainerPlugin( pluginClassName: 'ThirdPartyPlugin', ) void _() {} // ignore: unused_element diff --git a/packages/catalyst_builder_contracts/example/bin/example.dart b/packages/catalyst_builder_contracts/example/bin/example.dart index 928951e..78c771c 100644 --- a/packages/catalyst_builder_contracts/example/bin/example.dart +++ b/packages/catalyst_builder_contracts/example/bin/example.dart @@ -1,17 +1,18 @@ +import 'package:catalyst_builder/catalyst_builder.dart'; import 'package:catalyst_builder_contracts/catalyst_builder_contracts.dart'; import 'package:catalyst_builder_contracts_example/my_service.dart'; import 'example.catalyst_builder.plugin.g.dart'; -@GenerateServiceProviderPlugin( - // Enter a name that is used for the service provider class - pluginClassName: 'ExampleProviderPlugin', +@GenerateServiceContainerPlugin( + // Enter a name that is used for the service container class + pluginClassName: 'ExampleContainerPlugin', ) void main() { - final provider = ServiceContainer(); - provider.useExampleProviderPlugin(); - provider.boot(); + final container = ServiceContainer(); + container.useExampleContainerPlugin(); + container.boot(); - final service = provider.resolve(); + final service = container.resolve(); service.sayHello(); } diff --git a/packages/catalyst_builder_contracts/example/pubspec.yaml b/packages/catalyst_builder_contracts/example/pubspec.yaml index d67694f..540c24e 100644 --- a/packages/catalyst_builder_contracts/example/pubspec.yaml +++ b/packages/catalyst_builder_contracts/example/pubspec.yaml @@ -10,15 +10,13 @@ environment: # Add regular dependencies here. dependencies: catalyst_builder_contracts: + catalyst_builder: dev_dependencies: build_runner: - catalyst_builder: dependency_overrides: catalyst_builder_contracts: path: ../ catalyst_builder: path: ../../catalyst_builder - catalyst_builder_container: - path: ../../catalyst_builder_container diff --git a/packages/catalyst_builder_contracts/lib/catalyst_builder_contracts.dart b/packages/catalyst_builder_contracts/lib/catalyst_builder_contracts.dart index ef88c61..390a4f1 100644 --- a/packages/catalyst_builder_contracts/lib/catalyst_builder_contracts.dart +++ b/packages/catalyst_builder_contracts/lib/catalyst_builder_contracts.dart @@ -1,8 +1,8 @@ +export 'src/abstract_service_container.dart'; export 'src/annotation/annotation.dart'; export 'src/exception/exception.dart'; export 'src/lazy_service_descriptor.dart'; +export 'src/service_container_plugin.dart'; export 'src/service_descriptor.dart'; export 'src/service_lifetime.dart'; -export 'src/service_provider.dart'; export 'src/service_registry.dart'; -export 'src/service_provider_plugin.dart'; diff --git a/packages/catalyst_builder_contracts/lib/src/service_provider.dart b/packages/catalyst_builder_contracts/lib/src/abstract_service_container.dart similarity index 72% rename from packages/catalyst_builder_contracts/lib/src/service_provider.dart rename to packages/catalyst_builder_contracts/lib/src/abstract_service_container.dart index 17d228b..b4e2f29 100644 --- a/packages/catalyst_builder_contracts/lib/src/service_provider.dart +++ b/packages/catalyst_builder_contracts/lib/src/abstract_service_container.dart @@ -1,9 +1,9 @@ import '../catalyst_builder_contracts.dart'; -/// Describes a simple ServiceProvider -abstract interface class ServiceProvider { - /// Additional provider parameters. - /// If a service is not registered, the provider will also look inside +/// Describes a simple service container +abstract interface class AbstractServiceContainer { + /// Additional container parameters. + /// If a service is not registered, the container will also look inside /// the [parameters]. If there is a entry that match the name of the service /// parameter and the type matches the expected type, this parameter is used. Map get parameters; @@ -25,11 +25,11 @@ abstract interface class ServiceProvider { bool has([Type? type]); /// Boot the service container. - /// While booting the service provider, preloaded services are instantiated. + /// While booting the service container, preloaded services are instantiated. void boot(); - /// Creates a new service provider with additional services and parameters. - ServiceProvider enhance({ + /// Creates a new service container with additional services and parameters. + AbstractServiceContainer enhance({ List services = const [], Map parameters = const {}, }); @@ -47,6 +47,6 @@ abstract interface class ServiceProvider { /// [T]. If no parameter exists, return null; T? tryResolveOrGetParameter(String parameter); - /// Applies a plugin to the service provider - void applyPlugin(ServiceProviderPlugin plugin); + /// Applies a plugin to the service container + void applyPlugin(ServiceContainerPlugin plugin); } diff --git a/packages/catalyst_builder_contracts/lib/src/annotation/annotation.dart b/packages/catalyst_builder_contracts/lib/src/annotation/annotation.dart index a549387..5bf9ab7 100644 --- a/packages/catalyst_builder_contracts/lib/src/annotation/annotation.dart +++ b/packages/catalyst_builder_contracts/lib/src/annotation/annotation.dart @@ -1,4 +1,4 @@ -export 'generate_service_provider_plugin.dart'; +export 'generate_service_container_plugin.dart'; export 'inject.dart'; export 'preload.dart'; export 'service.dart'; diff --git a/packages/catalyst_builder_contracts/lib/src/annotation/generate_service_provider_plugin.dart b/packages/catalyst_builder_contracts/lib/src/annotation/generate_service_container_plugin.dart similarity index 70% rename from packages/catalyst_builder_contracts/lib/src/annotation/generate_service_provider_plugin.dart rename to packages/catalyst_builder_contracts/lib/src/annotation/generate_service_container_plugin.dart index 6a49de2..1520eab 100644 --- a/packages/catalyst_builder_contracts/lib/src/annotation/generate_service_provider_plugin.dart +++ b/packages/catalyst_builder_contracts/lib/src/annotation/generate_service_container_plugin.dart @@ -1,11 +1,11 @@ /// Mark the file which contains this annotation as the entry point. -class GenerateServiceProviderPlugin { +class GenerateServiceContainerPlugin { /// Set this property for setting the class name of the generated - /// service provider plugin. + /// service container plugin. final String pluginClassName; /// Mark this file as the entry point for the plugin - const GenerateServiceProviderPlugin({ + const GenerateServiceContainerPlugin({ required this.pluginClassName, }); } diff --git a/packages/catalyst_builder_contracts/lib/src/annotation/inject.dart b/packages/catalyst_builder_contracts/lib/src/annotation/inject.dart index b4b571a..80083bb 100644 --- a/packages/catalyst_builder_contracts/lib/src/annotation/inject.dart +++ b/packages/catalyst_builder_contracts/lib/src/annotation/inject.dart @@ -1,18 +1,14 @@ -import '../service_provider.dart'; - /// Inject a specific parameter or a list of services with a specific tag. /// You can only use one property. class Inject { - /// If [tag] is set, the provider will inject an array with all services with the given tag. + /// If [tag] is set, the container will inject an array with all services with + /// the given tag. /// If no services are tagged with the tag, an empty list will be injected. final Symbol? tag; - /// The name of the bound parameter inside [ServiceProvider.parameters]. + /// The name of the bound parameter inside [AbstractServiceContainer.parameters]. final String? parameter; /// Creates a new inject annotation. - const Inject({ - this.tag, - this.parameter, - }); + const Inject({this.tag, this.parameter}); } diff --git a/packages/catalyst_builder_contracts/lib/src/annotation/preload.dart b/packages/catalyst_builder_contracts/lib/src/annotation/preload.dart index 19ecdcf..e27fd6a 100644 --- a/packages/catalyst_builder_contracts/lib/src/annotation/preload.dart +++ b/packages/catalyst_builder_contracts/lib/src/annotation/preload.dart @@ -1,8 +1,6 @@ -import '../service_provider.dart'; - /// Mark a singleton service as preloaded. /// Preload means that an instance of the service -/// is created inside the [ServiceProvider.boot]. +/// is created inside the [AbstractServiceContainer.boot]. class Preload { /// Creates a new preload annotation. const Preload(); diff --git a/packages/catalyst_builder_contracts/lib/src/annotation/service.dart b/packages/catalyst_builder_contracts/lib/src/annotation/service.dart index cf127ce..80e570b 100644 --- a/packages/catalyst_builder_contracts/lib/src/annotation/service.dart +++ b/packages/catalyst_builder_contracts/lib/src/annotation/service.dart @@ -1,7 +1,6 @@ import '../service_lifetime.dart'; -import '../service_provider.dart'; -/// This class represents a service that is registered in the [ServiceProvider]. +/// This class represents a service that is registered in the [AbstractServiceContainer]. class Service { /// The lifetime of the service final ServiceLifetime lifetime; @@ -12,12 +11,12 @@ class Service { final Type? exposeAs; /// Tags for this service. Tags can be used to group services together and - /// receive all services in a specific groups from the ServiceProvider. + /// receive all services in a specific groups from the ServiceContainer. final List tags; /// Creates a new service. /// The [lifetime] describes, if the service should be stored in the service - /// provider after it's instantiated ([ServiceLifetime.singleton]) + /// container after it's instantiated ([ServiceLifetime.singleton]) /// or if always a fresh instance is created ([ServiceLifetime.transient]). const Service({ this.lifetime = ServiceLifetime.singleton, diff --git a/packages/catalyst_builder_contracts/lib/src/exception/container_already_booted_exception.dart b/packages/catalyst_builder_contracts/lib/src/exception/container_already_booted_exception.dart index 8e1b20f..bd94f39 100644 --- a/packages/catalyst_builder_contracts/lib/src/exception/container_already_booted_exception.dart +++ b/packages/catalyst_builder_contracts/lib/src/exception/container_already_booted_exception.dart @@ -1,11 +1,11 @@ import 'catalyst_builder_exception.dart'; /// An exception that is thrown when boot is called on a -/// already booted ServiceProvider. +/// already booted ServiceContainer. class ContainerAlreadyBootedException extends CatalystBuilderException { /// Creates a new [ContainerAlreadyBootedException] object. const ContainerAlreadyBootedException() : super( - 'The service provider was already booted.', + 'The service container was already booted.', ); } diff --git a/packages/catalyst_builder_contracts/lib/src/exception/container_not_booted_exception.dart b/packages/catalyst_builder_contracts/lib/src/exception/container_not_booted_exception.dart index b8814f4..5dc0a33 100644 --- a/packages/catalyst_builder_contracts/lib/src/exception/container_not_booted_exception.dart +++ b/packages/catalyst_builder_contracts/lib/src/exception/container_not_booted_exception.dart @@ -6,6 +6,6 @@ class ContainerNotBootedException extends CatalystBuilderException { /// Creates a new [ContainerNotBootedException] object. const ContainerNotBootedException() : super( - 'Service provider was not booted. Call ServiceContainer.boot() first.', + 'Service container was not booted. Call ServiceContainer.boot() first.', ); } diff --git a/packages/catalyst_builder_contracts/lib/src/service_provider_plugin.dart b/packages/catalyst_builder_contracts/lib/src/service_container_plugin.dart similarity index 68% rename from packages/catalyst_builder_contracts/lib/src/service_provider_plugin.dart rename to packages/catalyst_builder_contracts/lib/src/service_container_plugin.dart index 7c84415..9869c0f 100644 --- a/packages/catalyst_builder_contracts/lib/src/service_provider_plugin.dart +++ b/packages/catalyst_builder_contracts/lib/src/service_container_plugin.dart @@ -1,9 +1,9 @@ import '../catalyst_builder_contracts.dart'; -/// Defines a plugin for the [ServiceProvider] -abstract interface class ServiceProviderPlugin { +/// Defines a plugin for the [ServiceContainerPlugin] +abstract interface class ServiceContainerPlugin { /// Returns all known services that should be registered. - Map provideKnownServices(ServiceProvider p); + Map provideKnownServices(AbstractServiceContainer p); /// Returns a map for the exposing of services. Map provideExposes(); diff --git a/packages/catalyst_builder_contracts/lib/src/service_descriptor.dart b/packages/catalyst_builder_contracts/lib/src/service_descriptor.dart index e14fbec..9703819 100644 --- a/packages/catalyst_builder_contracts/lib/src/service_descriptor.dart +++ b/packages/catalyst_builder_contracts/lib/src/service_descriptor.dart @@ -1,6 +1,6 @@ import 'annotation/annotation.dart'; -/// This class is used for describing services in the service provider. +/// This class is used for describing services in the service container. class ServiceDescriptor { final Service _service; diff --git a/packages/catalyst_builder_contracts/lib/src/service_lifetime.dart b/packages/catalyst_builder_contracts/lib/src/service_lifetime.dart index fcc1430..c71a08d 100644 --- a/packages/catalyst_builder_contracts/lib/src/service_lifetime.dart +++ b/packages/catalyst_builder_contracts/lib/src/service_lifetime.dart @@ -1,7 +1,7 @@ /// Describes the lifetime of a service. enum ServiceLifetime { /// Only one instance of the service will be registered in - /// the service provider. + /// the service container. singleton, /// Every time the service is requested, a new instance will be created. diff --git a/packages/catalyst_builder_contracts/lib/src/service_registry.dart b/packages/catalyst_builder_contracts/lib/src/service_registry.dart index 23ce521..78c2d78 100644 --- a/packages/catalyst_builder_contracts/lib/src/service_registry.dart +++ b/packages/catalyst_builder_contracts/lib/src/service_registry.dart @@ -1,9 +1,9 @@ +import 'abstract_service_container.dart'; import 'annotation/annotation.dart'; -import 'service_provider.dart'; /// A function that can produce a [T]. Dependencies can be resolved using the -/// passed [ServiceProvider]. -typedef ServiceFactory = T Function(ServiceProvider); +/// passed [AbstractServiceContainer]. +typedef ServiceFactory = T Function(AbstractServiceContainer); /// Describes a class for registering services abstract interface class ServiceRegistry { diff --git a/packages/catalyst_builder_contracts/test/unit/exception/container_already_booted_exception_test.dart b/packages/catalyst_builder_contracts/test/unit/exception/container_already_booted_exception_test.dart index 5b250c6..3dd4b72 100644 --- a/packages/catalyst_builder_contracts/test/unit/exception/container_already_booted_exception_test.dart +++ b/packages/catalyst_builder_contracts/test/unit/exception/container_already_booted_exception_test.dart @@ -5,6 +5,6 @@ void main() { test('constructor', () { var ex = const ContainerAlreadyBootedException(); expect(ex, const TypeMatcher()); - expect(ex.message, equals('The service provider was already booted.')); + expect(ex.message, equals('The service container was already booted.')); }); } diff --git a/packages/catalyst_builder_contracts/test/unit/exception/container_not_booted_exception_test.dart b/packages/catalyst_builder_contracts/test/unit/exception/container_not_booted_exception_test.dart index a0114d7..c751d78 100644 --- a/packages/catalyst_builder_contracts/test/unit/exception/container_not_booted_exception_test.dart +++ b/packages/catalyst_builder_contracts/test/unit/exception/container_not_booted_exception_test.dart @@ -8,7 +8,7 @@ void main() { expect( ex.message, equals( - 'Service provider was not booted. Call ServiceProvider.boot() first.', + 'Service container was not booted. Call ServiceContainer.boot() first.', ), ); }); From 08e3efb932e989300574e2ea0a98d3b9dba92ea3 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Tue, 15 Apr 2025 07:05:07 +0200 Subject: [PATCH 6/9] fix: formatting --- packages/catalyst_builder/lib/catalyst_builder.dart | 2 +- packages/catalyst_builder/lib/src/builder/constants.dart | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/catalyst_builder/lib/catalyst_builder.dart b/packages/catalyst_builder/lib/catalyst_builder.dart index 60a5f07..9eaf77a 100644 --- a/packages/catalyst_builder/lib/catalyst_builder.dart +++ b/packages/catalyst_builder/lib/catalyst_builder.dart @@ -1 +1 @@ -export 'src/service_container.dart'; \ No newline at end of file +export 'src/service_container.dart'; diff --git a/packages/catalyst_builder/lib/src/builder/constants.dart b/packages/catalyst_builder/lib/src/builder/constants.dart index 6a7fce4..452bf3b 100644 --- a/packages/catalyst_builder/lib/src/builder/constants.dart +++ b/packages/catalyst_builder/lib/src/builder/constants.dart @@ -1,5 +1,6 @@ const String preflightExtension = '.catalyst_builder.preflight.json'; const String oldAnnotationsPrefix = 'package:catalyst_builder/src/annotation/'; -const String serviceContainerPluginExtension = '.catalyst_builder.plugin.g.dart'; +const String serviceContainerPluginExtension = + '.catalyst_builder.plugin.g.dart'; const String annotationsPrefix = 'package:catalyst_builder_contracts/src/annotation/'; From bae2bf57cc954859588fe8da8c1841fbaf71d220 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Tue, 15 Apr 2025 07:15:03 +0200 Subject: [PATCH 7/9] change: Prepare release 2.0.0-rc.1 --- packages/catalyst_builder_contracts/CHANGELOG.md | 11 +++++++++++ packages/catalyst_builder_contracts/pubspec.yaml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/catalyst_builder_contracts/CHANGELOG.md b/packages/catalyst_builder_contracts/CHANGELOG.md index 5d12c05..73788bd 100644 --- a/packages/catalyst_builder_contracts/CHANGELOG.md +++ b/packages/catalyst_builder_contracts/CHANGELOG.md @@ -1,3 +1,14 @@ +## 2.0.0-rc.1 + +### Breaking Changes + +- Removed `GenerateServiceProvider` annotation +- Renamed `GenerateServiceProviderPlugin` to `GenerateServiceContainerPlugin` +- Renamed `ProviderAlreadyBootedException` to `ContainerAlreadyBootedException` +- Renamed `ProviderNotBootedException` to `ContainerNotBootedException` +- Renamed `ServiceProvider` to `AbstractServiceContainer` +- Renamed `ServiceProviderPlugin` to `ServiceContainerPlugin` + ## 2.0.0-dev.2 ### Breaking Changes diff --git a/packages/catalyst_builder_contracts/pubspec.yaml b/packages/catalyst_builder_contracts/pubspec.yaml index cff959d..4e70ec2 100644 --- a/packages/catalyst_builder_contracts/pubspec.yaml +++ b/packages/catalyst_builder_contracts/pubspec.yaml @@ -1,6 +1,6 @@ name: catalyst_builder_contracts description: This is the contracts package for the catalyst_builder package. It includes annotations and marker interfaces. -version: 2.0.0-dev.2 +version: 2.0.0-rc.1 homepage: 'https://github.com/mintware-de/catalyst_builder' repository: 'https://github.com/mintware-de/catalyst_builder/tree/main/packages/catalyst_builder_contracts' documentation: https://github.com/mintware-de/catalyst_builder/wiki From be82dd730ebe43d5567b555a613bbca8d532ef70 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Tue, 15 Apr 2025 07:28:56 +0200 Subject: [PATCH 8/9] change: Prepare release 5.0.0-rc.1 --- packages/catalyst_builder/CHANGELOG.md | 6 ++++++ packages/catalyst_builder/pubspec.yaml | 9 ++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/catalyst_builder/CHANGELOG.md b/packages/catalyst_builder/CHANGELOG.md index a567df7..2f4535e 100644 --- a/packages/catalyst_builder/CHANGELOG.md +++ b/packages/catalyst_builder/CHANGELOG.md @@ -1,3 +1,9 @@ +## 5.0.0-rc.1 + +### Breaking Changes + +- Removed the generation of the service container. Check the [GenerateServiceProvider](https://github.com/mintware-de/catalyst_builder/wiki/v5#generateserviceprovider) section for upgrade guidance. + ## 5.0.0-dev.2 ### Changes diff --git a/packages/catalyst_builder/pubspec.yaml b/packages/catalyst_builder/pubspec.yaml index abcb3c1..2eb9335 100644 --- a/packages/catalyst_builder/pubspec.yaml +++ b/packages/catalyst_builder/pubspec.yaml @@ -1,6 +1,6 @@ name: catalyst_builder description: A lightweight and easy to use dependency injection container builder for dart. -version: 5.0.0-dev.2 +version: 5.0.0-rc.1 homepage: 'https://github.com/mintware-de/catalyst_builder' repository: 'https://github.com/mintware-de/catalyst_builder/tree/main/packages/catalyst_builder' documentation: 'https://github.com/mintware-de/catalyst_builder/wiki' @@ -34,14 +34,9 @@ dependencies: path: ^1.8.0 analyzer: '>=6.2.0 <8.0.0' yaml: ^3.0.0 - catalyst_builder_contracts: ^2.0.0-dev.2 + catalyst_builder_contracts: ^2.0.0-rc.1 dev_dependencies: test: any lints: any build_runner: ^2.2.0 - - -dependency_overrides: - catalyst_builder_contracts: - path: ../catalyst_builder_contracts \ No newline at end of file From 4bb1445799b4a84913c155efcaf97bf9ea36dbc4 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Tue, 15 Apr 2025 07:35:57 +0200 Subject: [PATCH 9/9] change: Exclude generated code from publishing to pub.dev --- packages/catalyst_builder/.pubignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/catalyst_builder/.pubignore b/packages/catalyst_builder/.pubignore index 5236e32..2313e40 100644 --- a/packages/catalyst_builder/.pubignore +++ b/packages/catalyst_builder/.pubignore @@ -1 +1,2 @@ -run_tests.sh \ No newline at end of file +run_tests.sh +**/*.g.dart \ No newline at end of file