MatrixParameters.AspNetCore
1.0.4
dotnet add package MatrixParameters.AspNetCore --version 1.0.4
NuGet\Install-Package MatrixParameters.AspNetCore -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MatrixParameters.AspNetCore" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MatrixParameters.AspNetCore --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MatrixParameters.AspNetCore, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MatrixParameters.AspNetCore as a Cake Addin #addin nuget:?package=MatrixParameters.AspNetCore&version=1.0.4 // Install MatrixParameters.AspNetCore as a Cake Tool #tool nuget:?package=MatrixParameters.AspNetCore&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MatrixParameters.AspNetCore
This library helps you to start using matrix parameters (or matrix URIs) in the route of API action.
Code Example
Startup
services.AddControllers(options =>
{
options.ModelBinderProviders.Insert(0, new SegmentPrefixAttributeModelBinderProvider());
options.ModelBinderProviders.Insert(1, new MatrixParameterAttributeModelBinderProvider());
});
services.AddRouting(options =>
{
options.ConstraintMap.Add("SegmentPrefix", typeof(SegmentPrefixConstraint));
});
Swagger
services.AddSwaggerGen(c =>
{
c.ParameterFilter<MatrixParameterFilter>();
c.DocumentFilter<MatrixDocumentFilter>();
});
Controller
// GET customers/2/bananas;color=yellow,green;rate=good/oregon
//
// This route with the segments {fruits} and {location} will match a path with two segments if they are not
// matched with the following two actions GetApplesFromWashington and GetApplesFromLocation. Both of their
// routes are more specific because of constraints, and thus matched prior to this.
[HttpGet]
[Route("{fruits}/{location}")]
public IActionResult GetFruitsFromLocation(
[SegmentPrefix] string fruits, // The fruits from the route segment {fruits}.
[MatrixParameter("bananas")] string[] color, // The matrix parameter color from the segment starting with "bananas". It is matched only if the fruits is "apples".
[SegmentPrefix] string location, // The location from the route segment {location}.
[MatrixParameter("{fruits}")] string[] rate) // The matrix parameter rate from the route segment "{fruits}".
{
var result = new Dictionary<string, string>
{
{ "fruits", fruits },
{ "color of bananas", Join(color) },
{ "location", location },
{ "rate of " + fruits, Join(rate) }
};
return Ok(result);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.3.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.