SimpleMapScope class
A ready-made CustomScope that keeps its instances in a map until you call destroy.
Use it when you control the start and end of the span yourself: a screen, a wizard, a test. Register one instance per scope name; after destroy it starts again empty.
// Beans in the 'screen' scope live until the checkout screen closes.
final screen = SimpleMapScope(conversationId: 'checkout');
context.beanFactory.registerScope('screen', screen);
final cart = context.getBean<CartState>(); // @Scope('screen')
// ... when the screen closes:
screen.destroy(); // runs @PreDestroy of CartState
Spring (Java): closest is SimpleThreadScope (or a hand-written
Scope backed by a map):
beanFactory.registerScope("thread", new SimpleThreadScope());
- Implemented types
Constructors
- SimpleMapScope({String? conversationId})
-
Creates an empty scope;
conversationIdis an optional id for it.
Properties
- conversationId → String?
-
An id of the current span (a session id, say), or
null.final - hashCode → int
-
The hash code for this object.
no setterinherited
-
names
→ Iterable<
String> -
The bean names whose instances the scope holds now.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
destroy(
) → void - Runs the destroy callbacks of every instance, newest first (later beans may use earlier ones), and empties the scope. The scope stays usable: the next lookup creates fresh instances.
-
get(
String name, Object objectFactory()) → Object -
The instance of the bean
namein the current span, created withobjectFactorywhen the scope does not hold one yet. Throw aStateErrorwhen the scope is not active right now (no screen open): the container reports it as aScopeNotActiveException.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerDestructionCallback(
String name, void callback()) → void -
Keeps
callback, which runs the destroy callbacks of the instance of the beanname; the scope calls it when it destroys that instance.override -
remove(
String name) → Object? -
Removes and returns the instance of the bean
name, ornull. Its destruction callback must not run: the caller owns the object now (destroyScopedBeanremoves it and then destroys it).override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited