How is execution passed from the clr class to Startup (startup.cs)?

The Startup class in asp.net 5 strikes me as a weird duck. It is not a Startup: ISomething or Startup: BaseSomething class, where the interface or base class is part of some Microsoft.AspNet assembly. *. No Startup is a simple class with correct magic method signatures generated by convention.

How is the transfer from DNX to Startup.ConfigureServices done?

Take for example a call:

dnx.exe . web

      

So. tells dnx that it can find project.json in the current folder. From there, finds the command associated with the "web" key. So if the local project.json has this:

"commands": {
"web" : Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
}

      

I'm going to take a hit that would combine it like the equivalent: dnx.exe. Microsoft.AspNet.Hosting - server Microsoft.AspNet.Server.WebListener --server.urls http: // localhost: 5000 "

I also get how dnx collects all sources (including dependencies) using options in project.json to compile memory, so we now have the user's assembly "MyAssembly" and all the dependent assemblies available to dnx. Dnx loaded Microsoft.AspNet.Hosting as a managed entry point. Therefore, execution moves from the unmanaged stub to the managed assembly Microsoft.AspNet.Hosting. Still?

The following parameters instruct Microsoft.AspNet.Hosting to host an instance of Microsoft.AspNet.Server.WebListener (specifically on localhost port 500). So, how does the Microsoft.AspNet.Server.WebListener "know" to look for a class named "Startup" in "MyAssembly". Is this just hardcoded into Microsoft.AspNet.Server.WebListener? At Microsoft.AspNet.Hosting?

Going to the Startup class seems like the last "magic". The execution before and after this is starting to get pretty clear, but I feel like I'm still missing something.

+3


source to share


2 answers


DNX knows how to load and run assemblies that have a named class Program

that has a named method Main

. You pass Microsoft.AspNet.Hosting

as the initial assembly to DNX when you run the command web

.

Hosting has a Basic Method .



This code , which is ultimately called from the Main method mentioned above, contains "Startup" in it. The real hardcode is here .

+4


source


I want to add some details to Victor's answer:



I wrote a series of posts that dive into the details of bootstrapping an ASP.NET 5 application from a native DNX host prior to processing requests . All these execution details are described in the messages.

+1


source







All Articles