Mundane.Hosting.AspNet
6.0.0
dotnet add package Mundane.Hosting.AspNet --version 6.0.0
NuGet\Install-Package Mundane.Hosting.AspNet -Version 6.0.0
<PackageReference Include="Mundane.Hosting.AspNet" Version="6.0.0" />
paket add Mundane.Hosting.AspNet --version 6.0.0
#r "nuget: Mundane.Hosting.AspNet, 6.0.0"
// Install Mundane.Hosting.AspNet as a Cake Addin #addin nuget:?package=Mundane.Hosting.AspNet&version=6.0.0 // Install Mundane.Hosting.AspNet as a Cake Tool #tool nuget:?package=Mundane.Hosting.AspNet&version=6.0.0
<img align="left" width="116" src="https://raw.githubusercontent.com/adambarclay/mundane-hosting-aspnet/main/build/Mundane.png"/>
Mundane.Hosting.AspNet
Mundane is a lightweight "no magic" web framework for .NET.
This package enables a Mundane application to be hosted with ASP.NET.
See the Mundane documentation for more information.
Getting Started
Install the Mundane.Hosting.AspNet nuget package, then in your ASP.NET startup code call app.UseMundane();
passing in the routing and dependencies configuration.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var dependencies = new Dependencies(
new Dependency<Configuration>(new Configuration(env)),
new Dependency<DataRepository>(request => new DataRepositorySqlServer(
request.Dependency<Configuration>().ConnectionString)));
var routing = new Routing(
routeConfiguration =>
{
routeConfiguration.Get("/", HomeController.HomePage);
routeConfiguration.Get("/data/{id}", DataController.GetData);
routeConfiguration.Post("/data/{id}", DataController.UpdateData);
});
app.UseMundane(dependencies, routing);
}
Executing Requests
Endpoints can be executed in a different part the ASP.NET pipeline by calling MundaneMiddleware.ExecuteRequest()
. For example you may want to do custom error handling while still making use of the Mundane engine.
Passing the current HttpContext
and the routing and dependencies configuration will execute the endpoint which matches the request.
public static async ValueTask ExecuteRequest(
HttpContext context,
DependencyFinder dependencyFinder,
Routing routing)
It is also possible to execute a specifc endpoint with:
public static async ValueTask ExecuteRequest(
HttpContext context,
DependencyFinder dependencyFinder,
MundaneEndpoint endpoint,
Dictionary<string, string> routeParameters)
The endpoint must be a MundaneEndpoint
which has the signature ValueTask<Response> Endpoint(Request request)
. Any of the other Mundane endpoint signatures can be converted to a MundaneEndpoint
by calling MundaneEndpointFactory.Create()
e.g.
MundaneEndpointFactory.Create(() => Response.Ok(o => Write("Hello World!")));
Since there is no routing information in this version of ExecuteRequest()
, you must also supply an appropriate routeParameters
dictionary for the endpoint. When called as part of the pipeline, Mundane creates a dictionary of parameters captured from the URL, e.g. for the route /my-endpoint/{id}
, called with /my-endpoint/123
, Mundane passes new Dictionary<string, string> { { "id", "123" } }
as routeParameters
.
If the endpoint does not require route parameters, pass an empty dictionary: new Dictionary<string, string>(0);
.
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. |
-
net6.0
- Mundane (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.