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.
source to share
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 .
source to share
I want to add some details to Victor's answer:
- DNX logic that finds entry points supports both static and standard instance methods .
- There is no communication between the server (WebListener in this case) and the Startup class and RequestDelegate. Glue if using the callback provided by the hosting layer to the server factory.
- The migration is not related to unmanaged code to ASP.NET hosting. This is where the entry point / application managed node is located on the DNX itself . This is where the support for the new project structure is implemented (still independent of ASP.NET).
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.
source to share