Dmitry Arestov Dmitry Arestov - 1 month ago 17
ASP.NET (C#) Question

ASP.NET App Initialization

In regular MVC app, the Application_Start method (and others) is not virtual. Therefore, this method must be called through reflection, and there are som naming convention. But why did they choose it like so? Instead, I would rather look at the base class' virtual methods and choose one to override. Now I have to go to docs. Why don't declare even handling methods in the base class.

P.S. In the new ASP.NET Core the Startup class even has no base class.


In former applications, the "entry" is not called from managed .NET code, naming convention is the most direct way, imagine static void Main.

For ASP.NET core applications, the entry is Main method, where you can specify a startup class using .UseStartup method of IWebHostBuilder extension. There is no constraint of IStartup is because its signature can be changed, for example:

public void Configure(IApplicationBuilder app)

public void Configure(IApplicationBuilder app, IHostingEnvironment env)

public void Configure(IApplicationBuilder app, IEmailService emailService)

The arguments are resolved by IServiceProvider, registered in ConfigureServices method.