Read the three articles, you will understand the basic working principle of ASP.NET Core MVC Framework

" 200 lines of code, seven objects - so that you understand the nature of ASP.NET Core framework of " so many readers have a deep understanding of the ASP.NET Core pipeline, know ASP.NET Core framework process flow for each request. For a long period of time, there are many private letter to me: Can you analyze the MVC framework in the same way. True MVC framework is actually very complex, so we are still in a similar manner drastic "cut" a lot of "minutiae", using a Mini version of the simulation framework will show up the core part of the real ASP.NET Core MVC. And Mini versions of ASP.NET Core frameworks, the Mini version of ASP.NET Core MVC framework uses the same real framework consistent design, and the same can be run directly. In order to better safeguard, I put these two simulation framework github on.

ASP.NET Core Mini: https://github.com/jiangjinnan/AspNetCoreMini

ASP.NET Core MVC Mini:https://github.com/jiangjinnan/AspNetCoreMvcMini

[Part I] routing integration

MVC framework built on the entire route middleware ( "ASP.NET Core 3 framework Secret" has devoted the next volume of routing middleware, this book is participating in Jingdong full 100-50 activities, 50% discount on the train before students can miss a) on. Whether facing Controller Model-View-Controller programming model, or Razor Pages page-oriented programming model, each request is directed are a certain Action, so only need to MVC each frame into a package Action routing endpoint (RouteEndpoint ), and by EndpointDataSource custom middleware can be registered on the routing. Benpian focus on the integration of the MVC framework and routing middleware, so we made the greatest simplification Action methods are defined: Action methods are non-parametric methods, so we do not consider the issue of binding parameters; the method of return Action task or values are Void, all requests processing tasks are implemented in the process. Read more ...

public class FoobarController: Controller
{
    public void Foo();
    public Task BarAsync();
    public ValueTask BazAsync();
}

[Novella] request response

We " [Part I]: Routing integration " will define the Action method Controller type is reduced to only return Task or method Void, and to make the method itself to complete, including to be appropriate for all requests processing tasks to the request, but true MVC framework without any restrictions on the return type of the Action method. In general, we prefer the return type of the method defined Action IActionResult, Task <IActionResult> or ValueTask <IActionResult>. If the method returns Action other types of objects, the object will eventually be converted into IActionResult object. Throughout the MVC framework for the process flow request, IActionResult is primarily responsible for responding to requests for work. This article, we will establish a simulation framework for further improvement of the above, contact with the return type of restriction method for Action. Read more ...

public class FoobarController: Controller
{
    public IActionResult Foo();
    public Task<IActionResult> BarAsync();   
    public ValueTask<IActionResult> BazAsync();
    public Foobar Qux();
    public Task<Foobar> QuuxAsync();
    public ValueTask<Foobar> CorgeAsync();
}

[Next] parameter binding

Action simulation framework assumed so far there is no method parameters, we know that MVC framework does not make restrictions on the parameter Action methods, which can contain any number and type of parameters. Once the "zero-argument" hypothesis removal, the method of implementation of Action becomes not so simple, because before executing the target method needs to bind all parameters. MVC framework uses a mechanism called "binding model (Model Binding)" to bind the target output parameter Action methods, which can be regarded as a request for MVC framework implementation process the most complex aspect. This article made progress to complete the existing framework, by implementing the above model binding exposure limits for Action method parameters. Read more ...

public class FoobarController: Controller
{
    public IActionResult Foo(Foo foo, Bar baz);
    public Task<IActionResult> BarAsync(Foo foo, Bar baz);   
    public ValueTask<IActionResult> BazAsync(Foo foo, Bar baz);
    public Foobar Qux(Foo foo, Bar baz);
    public Task<Foobar> QuuxAsync(Foo foo, Bar baz);
    public ValueTask<Foobar> CorgeAsync(Foo foo, Bar baz);
}

Guess you like

Origin www.cnblogs.com/artech/p/asp-net-core-mvc-mini.html