Repository navigation
Service Scopes - #40
Merged
Merged
Conversation
devtronic
force-pushed
the
feature/scoped-services
branch
3 times, most recently
from
November 12, 2026 07:44
4ae2fc3 to
3f9458e
Compare
- Renamed catalyst_builder_contracts to catalyst_builder_runtime (v7.0.0) - Moved ServiceContainer from catalyst_builder into catalyst_builder_runtime - catalyst_builder (v7.0.0) is now a pure code generator for dev_dependencies - Updated builder, example, third_party_dependency, CI, recipes and docs - Runtime and builder now share the same version number
Behavior is unchanged: the generated code is byte-identical.
The preflight builder now falls back to `ServiceLifetime.singleton` as the annotation default.
The generator emitted resolveOrGetParameter<Logger?> for required parameters whose type was nullable. The nullable Type never matched the registered service and null passed the 'is Logger?' parameter check, so resolution threw although the service was registered.
Constructor parameters now carry a TypeRef extracted by the preflight builder; the generator emits an explicit non-nullable type argument:
- tryResolveOrGetParameter<Logger>('logger') for required nullable and
- resolveOrGetParameter<Logger>(...) otherwise.
Unresolvable types keep inference and log a build warning.
- ServiceDescriptor factories receive the resolving container: - ServiceDescriptor(const Service(), (c) => MyService(c.resolve<Foo>())) and - produce(container) invokes them with it. - ServiceContainerPlugin.provideKnownServices() no longer takes the container parameter. - enhance() creates a child container linked via _parent instead of - copying descriptor maps. Lookups walk child -> parent; singletons are - built and cached by their owner container, transients by the - resolving container. Manual tagged registrations are inherited, - plugins are never applied to children. - The generator emits parameterless provideKnownServices() and (c) => ... factory lambdas.
- ServiceLifetime.scoped: one instance per scope, resolved by the innermost scope; resolving from the root throws ScopeRequiredException. - createScope() on AbstractServiceContainer; enhance() was removed. New ServiceScope interface with parent/isDisposed/dispose. - Disposable interface: instances created in a scope are disposed in - reverse creation order on dispose(); root dispose() disposes the root - singletons. Dispose is idempotent, collects errors and rethrows the - first one. Using a disposed scope throws ScopeDisposedException. - Circular dependency detection via a shared resolving stack on the - root; throws CircularDependencyException with the offending path. - Preflight warns when @preload is used on a scoped service. - The example demonstrates two scopes with asserts.
The plugin builder validates all collected services before generating code: - circular dependencies (error, with the path) - captive dependencies: singleton -> scoped (error) - required parameters of an unknown type (warning; the type may come from parameters, register() or another plugin) - duplicate exposeAs (warning, the last registration wins) The new 'validation' builder option (strict | warn | off, default: warn) controls whether warnings abort the build, are logged, or validation is skipped. Documented in the README and CHANGELOG.
Complete 6.x -> 7.x migration guide in packages/catalyst_builder/UPGRADE.md: TL;DR checklist, dependency and import migration, regeneration, detailed breaking changes with before/after code, new features and troubleshooting. All 'After' snippets were compile checked against the final API. Links added to the root README, both package READMEs and the changelogs.
devtronic
force-pushed
the
feature/scoped-services
branch
from
November 12, 2026 07:59
055d950 to
5f38d14
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking
The package catalyst_builder is now a pure code generator and must be added as a dev dependency.
The runtime (annotations, interfaces and the
ServiceContainer) moved to the new packagecatalyst_builder_runtime, which is added as a regular dependency:package:catalyst_builder/catalyst_builder.dartno longer exports theServiceContainer;import it from
package:catalyst_builder_runtime/catalyst_builder_runtime.dart.The generated service container plugin now references
catalyst_builder_runtimeinstead ofcatalyst_builder_contracts. Regenerate withdart run build_runner build.The generated plugin now implements
provideKnownServices()without a containerparameter and emits
(c) => MyService(...)factory lambdas that receive the resolvingcontainer. Generated files must be regenerated with
dart run build_runner build.Features
dependencies (
singletondepending onscoped) abort the build as errors; unknownrequired dependency types and duplicate
exposeAsare reported as warnings. The newvalidationbuilder option (strict|warn|off, defaultwarn) controls this.See the README for configuration.
@Service(lifetime: ServiceLifetime.scoped)is passed through to the generated plugin.@Preloadon a scoped service emits a build warning and is ignored.Fixes
ServiceLifetime.singleton(the annotationdefault) instead of
transientwhen thelifetimeof a@Serviceannotation cannotbe read.
The generator emits an explicit non-nullable type argument
(
c.tryResolveOrGetParameter<Logger>('logger')instead of relying on inference ofthe nullable type, which never matched the registered service). Parameters whose
type cannot be referenced by name still fall back to inference, now with a build
warning. The preflight data gained a
TypeReffor each resolvable parameter type.Assisted by Claude Code