catalyst_builder_runtime 7.0.0-beta.1
catalyst_builder_runtime: ^7.0.0-beta.1 copied to clipboard
Runtime for catalyst_builder: the ServiceContainer, annotations and interfaces. Add this as a regular dependency.
7.0.0-beta.1 #
See the upgrade guide for the full migration instructions.
Breaking #
-
The package has been renamed from
catalyst_builder_contractstocatalyst_builder_runtime. Update your imports topackage:catalyst_builder_runtime/catalyst_builder_runtime.dartand add it as a regular dependency:dependencies: catalyst_builder_runtime: ^7.0.0 -
The
ServiceContainerhas been moved fromcatalyst_builderinto this package. Import it fromcatalyst_builder_runtimeinstead ofcatalyst_builder. -
ServiceDescriptorfactories now receive the resolving container:ServiceDescriptor(const Service(), (c) => MyService(c.resolve<Foo>())).ServiceDescriptor.produce()becameproduce(AbstractServiceContainer container). -
ServiceContainerPlugin.provideKnownServices()no longer receives the container as a parameter. -
enhance()has been removed and replaced bycreateScope()with identical semantics: it creates a child container linked to its parent instead of copying all registrations. Singletons are always built and cached by the container that registered them: a root singleton can no longer see child-only dependencies (it now throwsDependencyNotFoundExceptionlike on the root). Services registered in a child stay invisible to the root. -
ServiceLifetimegained the valuescoped(at the end of the enum). Code with an exhaustiveswitchoverServiceLifetimemust handle the new case. -
AbstractServiceContainergained the memberscreateScope()anddispose(). Custom implementations ofAbstractServiceContainermust implement the new members.
Features #
- New lifetime
ServiceLifetime.scoped: one instance per scope, created and reused by the innermost scope that resolves it. Resolving a scoped service from the root container throws aScopeRequiredException– also viatryResolve, because it is a configuration error. AbstractServiceContainer.createScope()creates a child scope (with optional service and parameter overrides). Scopes implement the newServiceScopeinterface (parent,isDisposed,dispose()).- New interface
Disposable: instances created inside a scope that implement it are disposed in reverse creation order when the scope is disposed; the root container disposes its singletons ondispose(). Disposal is idempotent; all instances are disposed even if one throws, and the first error is rethrown. - Circular dependencies between services are detected while instantiating and throw the new
CircularDependencyExceptionwith the offendingpath(e.g.[A, B, A]).
Fixes #
ServiceNotFoundExceptionthrown byresolvenow reports the runtime type that was passed as argument instead of the static generic type.