Struct BinderContext
binder context supplied to custom request binders.
Implements
Inherited Members
Namespace: FastEndpoints
Assembly: FastEndpoints.dll
Syntax
public readonly struct BinderContext : IServiceResolverBase
Constructors
BinderContext(HttpContext, List<ValidationFailure>, JsonSerializerContext?, bool)
constructor of the binder context
Declaration
public BinderContext(HttpContext httpContext, List<ValidationFailure> validationFailures, JsonSerializerContext? jsonSerializerContext, bool dontAutoBindForms)
Parameters
Type | Name | Description |
---|---|---|
HttpContext | httpContext | the http context of the current request |
List<ValidationFailure> | validationFailures | the validation failure collection of the endpoint |
JsonSerializerContext | jsonSerializerContext | json serializer context of the endpoint if applicable |
bool | dontAutoBindForms | whether to enable auto binding of form data |
Properties
DontAutoBindForms
set 'true' to disable auto binding of form data which enables uploading and reading of large files without buffering to memory/disk. you can access the multipart sections for reading via the FormFileSectionsAsync() method.
Declaration
public bool DontAutoBindForms { get; init; }
Property Value
Type | Description |
---|---|
bool |
HttpContext
the http context of the current request
Declaration
public HttpContext HttpContext { get; init; }
Property Value
Type | Description |
---|---|
HttpContext |
JsonSerializerContext
if the current endpoint is configured with a json serializer context, it will be provided to the custom request binder with this property.
Declaration
public JsonSerializerContext? JsonSerializerContext { get; init; }
Property Value
Type | Description |
---|---|
JsonSerializerContext |
SerializerOptions
the configured json serializer options of the app, which was specified at app startup.
Declaration
public JsonSerializerOptions SerializerOptions { get; }
Property Value
Type | Description |
---|---|
JsonSerializerOptions |
ValidationFailures
a list of validation failures for the endpoint. you can add your own validation failures for properties of the request dto using this property.
Declaration
public List<ValidationFailure> ValidationFailures { get; init; }
Property Value
Type | Description |
---|---|
List<ValidationFailure> |
Methods
CreateScope()
if you'd like to resolve scoped or transient services from the MS DI container, obtain a service scope from this method and dispose the scope when the work is complete.
using var scope = CreateScope();
var scopedService = scope.Resolve<MyService>();
Declaration
public IServiceScope CreateScope()
Returns
Type | Description |
---|---|
IServiceScope |
Resolve(Type)
resolve an instance for the given type from the dependency injection container. will throw if unresolvable.
Declaration
public object Resolve(Type typeOfService)
Parameters
Type | Name | Description |
---|---|---|
Type | typeOfService | the type of the service to resolve |
Returns
Type | Description |
---|---|
object |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if requested service cannot be resolved |
Resolve<TService>()
resolve an instance for the given type from the dependency injection container. will throw if unresolvable.
Declaration
public TService Resolve<TService>() where TService : class
Returns
Type | Description |
---|---|
TService |
Type Parameters
Name | Description |
---|---|
TService | the type of the service to resolve |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if requested service cannot be resolved |
TryResolve(Type)
try to resolve an instance for the given type from the dependency injection container. will return null if unresolvable.
Declaration
public object? TryResolve(Type typeOfService)
Parameters
Type | Name | Description |
---|---|---|
Type | typeOfService | the type of the service to resolve |
Returns
Type | Description |
---|---|
object |
TryResolve<TService>()
try to resolve an instance for the given type from the dependency injection container. will return null if unresolvable.
Declaration
public TService? TryResolve<TService>() where TService : class
Returns
Type | Description |
---|---|
TService |
Type Parameters
Name | Description |
---|---|
TService | the type of the service to resolve |