Mundaneは、.NETの軽量の「魔法のない」Webフレームワークです。
このパッケージにより、asp.netでありふれたアプリケーションをホストできます。
詳細については、ありふれたドキュメントを参照してください。
mundane.hosting.aspnet nugetパッケージをインストールしてから、ASP.NETスタートアップコードコールapp.UseMundane();ルーティングと依存関係の構成を渡します。
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 ) ;
} エンドポイントはMundaneMiddleware.ExecuteRequest()を呼び出すことにより、ASP.NETパイプラインの別の部分で実行できます。たとえば、ありふれたエンジンを使用しながら、カスタムエラー処理を行うことをお勧めします。
現在のHttpContextとルーティングおよび依存関係の構成を渡すと、リクエストに一致するエンドポイントが実行されます。
public static async ValueTask ExecuteRequest (
HttpContext context ,
DependencyFinder dependencyFinder ,
Routing routing )以下でspecifcエンドポイントを実行することも可能です。
public static async ValueTask ExecuteRequest (
HttpContext context ,
DependencyFinder dependencyFinder ,
MundaneEndpoint endpoint ,
Dictionary < string , string > routeParameters )エンドポイントは、署名ValueTask<Response> Endpoint(Request request)を備えたMundaneEndpointでなければなりません。他のありふれたエンドポイント署名はMundaneEndpointFactory.Create()を呼び出すことにより、 MundaneEndpointに変換できます。
MundaneEndpointFactory . Create ( ( ) => Response . Ok ( o => Write ( "Hello World!" ) ) ) ;このバージョンのExecuteRequest()にはルーティング情報がないため、エンドポイントに適切なrouteParameters辞書も提供する必要があります。パイプラインの一部として呼び出されると、MundaneはURLからキャプチャされたパラメーターのrouteParametersを作成します。たとえば、Route /my-endpoint/{id}で、 new Dictionary<string, string> { { "id", "123" } } /my-endpoint/123で呼び出されます。
エンドポイントがルートパラメーターを必要としない場合は、空の辞書を渡します。 new Dictionary<string, string>(0); 。