????Run()?????????????Middleware????????????????????д?????????????????????
???????????????????Middleware??
public class DefaultMiddleware:IMiddleware
{
public Request ProcessRequest(Request request)
{
request.Process("default request"?? "processed by defaultMiddleware");
return request;
}
public Response ProcessResponse(Response response)
{
response.Process("default response"?? "processed by defaultMiddleware");
return response;
}
}
????????Middleware??????????????????д???????????????????????
public static void UseDefaultMiddleware(this IApplicationBuilder applicationBuilder)
{
applicationBuilder.Use();
}
public static void Use(this IApplicationBuilder applicationBuilder)
where TMiddleware:IMiddleware
{
var middleware = applicationBuilder.Container.Resolve();
applicationBuilder.Use(middleware);
}
????д????????????

????д?????Middleware??
public class GreetingMiddleware:IMiddleware
{
public Request ProcessRequest(Request request)
{
request.Process("hello?? request"??"processed by greetingMiddleware");
return request;
}
public Response ProcessResponse(Response response)
{
response.Process("hello?? request"?? "processed by greetingMiddleware");
return response;
}
}
??????д?????

???????????????????
????????????Owin??ASP.NET Core??????????????????????????????????????????????????????????????Middleware?????δ???????
?????????????????????Middleware??????Func??????????????????????

???????Middleware???????????Func?? Func>???????????Middleware?????????????????????????
public Func?? Func> Process()
{
Func?? Func> middleware = next =>
{
Func process = context =>
{
/*process request*/
next(context);
/*process response*/
return context;
};
return process;
};
return middleware;
}
?????????????????????????????????Middleware??????????Func?????????????????????????????У?
????public delegate Context RequestDelegate(Context context);
???????????RequestDelegate?????????Middleware??
????public IApplication Build()
????{
????RequestDelegate request = context => context;
????_middlewares.Reverse();
????foreach (var middleware in _middlewares)
????{
????request = middleware(request);
????}
????return new Application(request);
????}
?????????????????Middleware??
public class DefaultMiddleware:IMiddleware
{
public Func Request()
{
Func request = next =>
{
return context =>
{
context.Request.Process("default request"?? "processed by defaultMiddleware");
next(context);
context.Response.Process("default response"?? "processed by defaultMiddleware");
return context;
};
};
return request;
}
}
???????д??????????https://git.oschina.net/richieyangs/Pipeline.Middleware.git