Repository navigation
Partie Contexts
A context lists the values a handler, Provider, or Partie needs. Partie builds it from its constructor parameters. Each parameter has one attribute that selects the value's source.
Use Unit when there are no dependencies. Otherwise, use a concrete reference type with exactly one constructor accessible to the route project. A record with a primary constructor works well:
public sealed record CourseSearchContext(
[Inject] ICourseCatalog Catalog,
[Provide] AcademicYear Year
);Constructor parameters must be passed by value and have exactly one of [Inject], [Provide], [Decorate], or [Parameter].
[Inject] resolves a required service from the framework's dependency injection system:
services.AddScoped<ICourseCatalog, CourseCatalog>();public sealed record CourseSearchContext([Inject] ICourseCatalog Catalog);The service follows its registered lifetime. Here, services is your application's IServiceCollection. A value produced by a Provider does not satisfy [Inject]; use [Provide] for that value.
[Provide] selects an output from a registered Provider or Partie by its exact type:
public sealed record CourseSearchContext([Provide] AcademicYear Year);If the selected source is a Provider, Partie runs it on demand. Multiple consumers share the value produced by that registration within the invocation.
[Provide] selects the latest matching source and can resolve sources registered before or after the consumer. Each source resolves its own context at its registration position, so moving registrations can change which dependencies it receives.
When there is no earlier exact source, a single request property of the requested type can also supply the value. Two request properties with that type are ambiguous. Use distinct value types when values have different meanings; two string outputs are both sources for [Provide] string.
[Decorate] selects the latest earlier output of the exact type. Use it when a step transforms a value already registered in the pipeline:
public sealed record CampusYearContext(
[Decorate] AcademicYear Year,
[Parameter] string Campus
);A Provider or Partie using this context can pass a replacement AcademicYear to next. Later consumers then receive that replacement. Register the original year source before the transforming step. [Decorate] cannot pull a source from later in the route.
Request IEnumerable<T> to receive multiple exact T outputs:
public sealed record CourseSearchContext([Provide] IEnumerable<AcademicYear> Years);[Provide] IEnumerable<T> includes matching sources on both sides of the consumer. [Decorate] IEnumerable<T> includes only earlier sources, in registration order. Both work with no matching sources and supply an empty collection. A source does not include itself in its own collection dependency.
[Parameter] takes a value from the generated registration attribute. This Provider context makes the year configurable at each registration:
public sealed record AcademicYearContext(
[Parameter] string Name = "2026-2027"
);For a Provider named AcademicYearProvider, the generated attribute accepts that argument:
[AcademicYearProvider("2027-2028")]
...A constructor parameter without a default creates a required attribute argument. A default makes the argument optional. Repeated registrations may supply different values. Bundles forward these parameters through their members.
Partie resolves Provider and Partie dependencies at compile time. A missing source, dependency cycle, ambiguous request property, or invalid context constructor prevents the affected pipeline from being generated. Check the named context parameter and its registration order. Dependency injection still resolves services at runtime.
See Providers for creating values and Parties for ordered behavior.
- Home
- Getting started
-
Package guides
- Partie
- Expo
-
Mise
- Database setup
- Table mappings
- Aliases
- Relationships
- Result rows
- SQL interpolation
- Queries
- Filtering
- Joins
- Aggregation
- Paging and ordering
- Subqueries
- Set operations
- Common table expressions
- Readers
- Streaming
- Writers
- Inserts
- Updates
- Deletes
- Returned rows
- Custom SQL and procedures
- Transactions
- Resource lifetimes
- Database dialects
- Diagnostics
- Integrations
- Recipes
- Reference
- Troubleshooting
- Development