BaseAggregate
Base class for aggregate root entities -- the primary building block for modeling domain concepts that enforce consistency rules and manage state changes.
See Aggregates guide for practical usage and Aggregates concept for design rationale.
Bases: BaseEntity
Base class for aggregate root entities -- the primary building block for modeling domain concepts.
Aggregates enforce consistency rules and define transaction boundaries.
They inherit all entity capabilities (fields, identity, invariants) and add
versioning for optimistic concurrency, event raising via raise_(), and
event-sourcing support via _apply() / from_events().
Meta Options
| Option | Type | Description |
|---|---|---|
event_sourced |
bool |
Enable event-sourcing mode (default: False). |
fact_events |
bool |
Auto-generate fact events on persistence (default: False). |
stream_category |
str |
Override the event stream category name. |
provider |
str |
The persistence provider name (default: "default"). |
schema_name |
str |
The storage table/collection name. |
auto_add_id_field |
bool |
Whether to auto-inject an id field (default: True). |
Source code in src/protean/core/aggregate.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
raise_
raise_(event: Any) -> None
Raise a domain event on this aggregate.
Enriches the event with metadata (identity, stream, sequence,
checksum) and appends it to self._events.
Source code in src/protean/core/aggregate.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
from_events
classmethod
from_events(events: list[Any]) -> BaseAggregate
Event-Sourcing: reconstruct an aggregate from a list of events.
Creates a blank aggregate via _create_for_reconstitution() and
applies all events uniformly through _apply(). The first event's
@apply handler must set ALL fields including identity.
| RAISES | DESCRIPTION |
|---|---|
IncorrectUsageError
|
If |
Source code in src/protean/core/aggregate.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |