Skip to content

Attributes

Every attribute in the framework, by the package it comes from.

Modules and application

Hardened.Shared.Runtime.Attributes

AttributeTargetPurpose
[HardenedModule]ClassMarks a partial class as a module entry point. Generates the module and a companion attribute named after it
[ConfigurationModel]ClassMarks a partial class as a configuration model. Generates the interface, the properties and the registration
[FromEnvironmentVariable(name)]FieldPopulates a configuration field from an environment variable
[HideConfigurationField]FieldExcludes a field from the generated interface
[ConfigurationProvider]ClassMarks a configuration provider

Every [HardenedModule] class also produces <Name>Attribute, which is how one module imports another — [AspNetCoreRuntime], [HardenedWebModule], [DynamoDbModule] and the rest are all generated this way. See Modules.

Service registration

DependencyModules.Runtime.Attributes, from DependencyModules

AttributeTargetPurpose
[SingletonService]ClassOne instance for the application
[ScopedService]ClassOne instance per scope
[TransientService]ClassA new instance per resolution
[DependencyModule]ClassThe DependencyModules module attribute [HardenedModule] builds on
[Decorator]ClassWraps a registered service
[Decorate]ClassApplies a decorator to a service you do not control
[Intercept]ClassRoutes members through generated interceptors
[IfEnvironment] / [IfNotEnvironment]ClassRegisters only in (or outside) named environments
[IfEnvironmentValue] / [IfNotEnvironmentValue]ClassRegisters based on an environment variable
[CrossWireService]ClassCross-wires a registration between modules

All take As to narrow the service type, and Using to choose the registration semantics.

Requests

Hardened.Requests.Abstract.Attributes

AttributeTargetPurpose
[HardenedFunction(name?)]MethodA function handler, addressed by name
[Handler]ClassMarks an implementation of a generated OpenAPI service interface
[FromBody]ParameterBinds from the request body
[FromServices]ParameterBinds from the container
[Output<T>]MethodHands the response to a view or other output instead of serialising it. Takes the response out of negotiation: unsupported Accept is a 406
[RawResponse(contentType?)]MethodCommits the response to a content type and writes the value unstructured. Defaults to text/plain

ICustomBindingAttribute is the interface an attribute implements to bind a parameter itself — see Parameter binding.

Hardened.Requests.Runtime.Filters

AttributeTargetPurpose
[Retry(Retries, SleepTime)]MethodRetries the handler. Defaults: 3 retries, 500 ms

Authorization

Hardened.Requests.Runtime.Authorization

AttributeTargetPurpose
[AuthorizeGrants(grants)]Class, methodRequires every grant named. What a generator emits from a specification
[AuthorizeGrants<T>]Class, methodRequires every grant in the IGrantProvider T names. The typed spelling
[Authorize<TPolicy>]Class, methodRequires the policy's requirement. The only form that can express or
[AllowAnonymous]Class, methodMakes an operation public on purpose. Beats every requirement on the same handler, including a convention
[RequireAuthorization]Class, assemblyOn the module: a handler declaring nothing is denied rather than public, and reported as HAUTH001 at build

Every one of these stacks as and. Attributes on a method, attributes on its controller, attributes inherited from a base attribute and requirements added by an IAuthorizationConvention are all conjoined into the single Requirement the pipeline reads. Alternatives are expressible only inside a single policy.

[AuthorizeGrants] is not sealed — deriving from it is one of the two ways to require grants without writing strings. IAuthorizeAttribute is the interface anything the pipeline honours implements, including attributes of your own, and it is what the HAUTH001 diagnostic tests.

See Authorization.

Web

Hardened.Web.Runtime.Attributes

AttributeTargetPurpose
[Get(path)]MethodA GET route
[Post(path)]MethodA POST route
[Put(path)]MethodA PUT route
[Delete(path)]MethodA DELETE route
[Patch(path)]MethodA PATCH route
[BasePath(path)]Class, assemblyPrefixes every route beneath it
[FromQueryString(name?)]ParameterBinds from the query string
[FromHeader(name?)]ParameterBinds from a request header
[CacheControl]MethodSets cache headers. MaxAge, Type
[WebLibrary]ClassMarks a web library entry point
[Tag(name)]ClassThe OpenAPI tag this controller's operations group under. Defaults to the class name minus Controller
[Server(url, description?)]Class, assemblyA base URL the generated document lists under servers
[CaseInsensitiveRoutes]ClassMatches this module's routes without regard to case
[RouteConstraint(name)]MethodDeclares a route constraint. static bool(ReadOnlySpan<char>)

The verb attributes also declare SuccessStatus, the status a successful response answers with and the document publishes; unset means 200. The NullReturnStatus, ValidationErrorStatus and ErrorStatus properties they once carried are gone. See Returning null for what decides those statuses.

Templates

Hardened.Templates.RazorBlade

AttributeTargetPurpose
[Enable<HardenedRazorTemplates>]ClassGenerates a RazorBlade template base for a module
[TemplateBase(typeof(T<>))]ClassOn an engine's marker: the class a generated base derives from
[TemplateContentType(type)]ClassOn an engine's marker: what views on that base produce

[Enable<T>] itself lives in Hardened.Shared.Runtime.Attributes and is the framework's one name for every optional generated feature. It requires new(), and a marker that is also a DependencyModules module has its registrations applied too. A view is named on a handler with [Output<T>].

Console

Hardened.Commands.Attributes

AttributeTargetPurpose
[Command(command)]ClassA command. ParentCommand, Description
[Option]PropertyRenames an option or gives it help text
[FileOption]PropertyAn option whose value is a path
[ExcludeOption]PropertyA property that is not an option

Testing

Hardened.Shared.Testing.Attributes

AttributeTargetPurpose
[HardenedTest]MethodAn xUnit fact that boots the application and injects the parameters
[HardenedTestEntryPoint(type)]Assembly, class, methodNames the application module under test
[Mock]ParameterSubstitutes an NSubstitute mock and hands it to the test
[EnvironmentName(name)]Assembly, class, methodThe environment name for the test. Defaults to test
[EnvironmentValue(variable, value)]Assembly, class, methodSets an environment value for the test

Hardened.Web.Testing

AttributeTargetPurpose
[WebTesting]AssemblyInstalls ITestWebApp

AWS

From Hardened.Amz.

AttributeNamespacePurpose
[LambdaFunctionModule]Hardened.Amz.Function.Lambda.Runtime.DependencyInjectionLambda invocation runtime and the request pipeline. Required by every function application
[LambdaWebModule]Hardened.Amz.Web.Lambda.Runtime.DependencyInjectionAPI Gateway runtime and the web pipeline. Required by every Lambda web application
[LambdaWebApplication(Version)]Hardened.Amz.Web.Lambda.RuntimeStates the payload format. ProxyIntegrationType.HttpApiV2 is the default and the only implemented value; .ApiGateway is HRDAWS001
[StreamingLambdaWebModule]Hardened.Amz.Web.Lambda.StreamingResponse-streaming web runtime
[StreamingLambdaFunctionModule]Hardened.Amz.Function.Lambda.StreamingResponse-streaming function runtime
[SqsLambda]Hardened.Amz.Function.Sqs.RuntimeSQS batch runtime. Applied alongside [LambdaFunctionModule]
[DynamoStreamLambda]Hardened.Amz.Function.DDB.RuntimeDynamoDB Streams runtime. Applied alongside [LambdaFunctionModule]
[DynamoDbModule]Hardened.Amz.DynamoDbClientRegisters IDynamoDbClientProvider
[HardenedCdk]Hardened.Amz.CdkCDK deployment application
[NewImage] / [OldImage]Hardened.Amz.Function.DDB.Runtime.AttributesBinds a stream record's images
[FromContext(name?)]Hardened.Amz.Function.Lambda.RuntimeBinds a named value from the invocation's headers
[ThrowException]Hardened.Amz.Function.Lambda.RuntimeRethrows, so the invocation fails instead of returning the error
[LambdaFunctionTesting]Hardened.Amz.Function.Lambda.TestingInstalls the Lambda test harnesses
[LocalDynamoDb(Image?)]Hardened.Amz.DynamoDbClient.TestingPoints the client provider at DynamoDB Local in a container

Released under the MIT License.