2

In Startup.cs I have a Startup class which exposes ConfigureServices() and Configure(). The Startup class is used in the Main() code path as such...

webBuilder.UseStartup<Startup>();

Many questions:

  • How/why are Startup callback methods inferred if Startup does not implement an interface?
  • Is the runtime using Reflection?
  • Why isn't the generic type an interface?
  • What if Startup class does not implement ConfigureServices() and Configure()?
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
triple.vee
  • 126
  • 1
  • 7
  • Read about fundamentals in [docs](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-3.1) – Mateech May 08 '20 at 17:49

1 Answers1

2

Even though the ASP.NET Core uses reflection in order to call ConfigureServices and Configure methods, you can implement the IStartup interface.

It is defined under the Microsoft.AspNetCore.Hosting namespace.

The main purpose why it exists is that it supports integration testing. For further details, please check this excellent article.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75