Skip to content

[Context]: add scoped context lifecycle and cancellation aware execution #6

Description

@rian-be

Summary

Add richer context lifecycle APIs for scoped usage, cancellation-aware execution, and lightweight lifecycle metadata.

Goal

Make the library easier to use in real application code where callers need manual scope control, cancellation propagation, and a clearer view of context lifetime.

Problem

The current API is intentionally small, but the only practical way to interact with context is still centered around the async execution helpers. That is good for simple flows, but it leaves a few common use cases awkward:

  • manual scope handling with using
  • cancellation-aware execution paths
  • explicit access to previous and current context during a scope
  • lightweight lifecycle metadata for diagnostics

Scope

  • Add first class context scope abstraction
  • Expose manual begin/end scope APIs on the manager
  • Add cancellation aware ExecuteInContext(...) overloads
  • Keep synchronous convenience overloads aligned with the async API
  • Surface lifecycle metadata such as start time, end time, and disposal state
  • Keep the new APIs small enough to stay in the core package
  • Update examples so the new scope model is discoverable

Design Expectations

  • The new API should stay thin and predictable.
  • Cancellation support should not introduce hidden global state.
  • Scope metadata should be useful for diagnostics without becoming full audit system.
  • Existing async execution behavior should remain unchanged.

Acceptance Criteria

  • The package exposes manual scope based API for context activation.
  • The package supports cancellation-token based execution helpers.
  • The scope model exposes enough metadata to inspect lifecycle state.
  • Existing execution helpers keep working as before.

Non Goals

  • No governance layer.
  • No persistence backend.
  • No event bus or subscriber model.
  • No ASP.NET specific integration.
  • No policy engine.

Notes

This issue is intended to cover the next useful extension of the core library without moving into larger platform abstraction.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions