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..31f0747 100644
--- a/README.md
+++ b/README.md
@@ -3,15 +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. | [](https://pub.dartlang.org/packages/catalyst_builder)


 |
-| [`catalyst_builder_container`](./packages/catalyst_builder_container) | The container package. Use this package to resolve services from the container. | [](https://pub.dartlang.org/packages/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. | [](https://pub.dartlang.org/packages/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. | [](https://pub.dartlang.org/packages/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. | [](https://pub.dartlang.org/packages/catalyst_builder_contracts)


 |
## Roadmap
@@ -20,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/.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
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/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_container/lib/catalyst_builder_container.dart b/packages/catalyst_builder/lib/catalyst_builder.dart
similarity index 78%
rename from packages/catalyst_builder_container/lib/catalyst_builder_container.dart
rename to packages/catalyst_builder/lib/catalyst_builder.dart
index 11608a5..9eaf77a 100644
--- a/packages/catalyst_builder_container/lib/catalyst_builder_container.dart
+++ b/packages/catalyst_builder/lib/catalyst_builder.dart
@@ -1,3 +1 @@
-library;
-
export 'src/service_container.dart';
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/constants.dart b/packages/catalyst_builder/lib/src/builder/constants.dart
index bc0713b..452bf3b 100644
--- a/packages/catalyst_builder/lib/src/builder/constants.dart
+++ b/packages/catalyst_builder/lib/src/builder/constants.dart
@@ -1,6 +1,6 @@
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/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 80%
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 ea6c698..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;
@@ -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,
);
}
@@ -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();
@@ -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_container/lib/src/service_container.dart b/packages/catalyst_builder/lib/src/service_container.dart
similarity index 92%
rename from packages/catalyst_builder_container/lib/src/service_container.dart
rename to packages/catalyst_builder/lib/src/service_container.dart
index 05fd879..b46da05 100644
--- a/packages/catalyst_builder_container/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 = {};
@@ -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) {
@@ -107,7 +107,7 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry {
void _ensureBoot() {
if (_booted == false) {
- throw const ProviderNotBootedException();
+ throw const ContainerNotBootedException();
}
}
@@ -137,7 +137,7 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry {
}
@override
- ServiceProvider enhance({
+ AbstractServiceContainer enhance({
List services = const [],
Map parameters = const {},
}) {
@@ -167,9 +167,9 @@ class ServiceContainer implements ServiceProvider, ServiceRegistry {
}
@override
- void applyPlugin(ServiceProviderPlugin plugin) {
+ void applyPlugin(ServiceContainerPlugin plugin) {
if (_booted) {
- throw const ProviderAlreadyBootedException();
+ throw const ContainerAlreadyBootedException();
}
_appliedPlugins.add(plugin);
_knownServices.addAll(plugin.provideKnownServices(this));
diff --git a/packages/catalyst_builder/pubspec.yaml b/packages/catalyst_builder/pubspec.yaml
index 419e70c..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 provider builder for dart.
-version: 5.0.0-dev.2
+description: A lightweight and easy to use dependency injection container builder for dart.
+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,7 +34,7 @@ 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
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_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 @@
-[](https://github.com/mintware-de/catalyst_builder/blob/main/packages/catalyst_builder_container/LICENSE)
-[](https://pub.dartlang.org/packages/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/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 997eba3..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 {
- 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