Untitled Deck Flashcards
What’s the main difference between ASP.NET and .NET (Core/.NET 9)?
.NET 9 is cross-platform, modular, faster, and does not use System.Web. It uses a middleware pipeline and has built-in dependency injection.
Which core file replaces Global.asax in .NET 9?
Program.cs (and optionally Startup.cs in older versions) replaces Global.asax for application startup and configuration.
What are the three main DI lifetimes in .NET 9?
Transient: New instance every time
Scoped: One instance per HTTP request
Singleton: One instance for the app’s lifetime
When should you use Transient?
When the service is lightweight and stateless — ideal for short-lived operations or logic.
When should you use Scoped?
When the service needs to maintain state throughout a single request, like a DbContext.
When should you use Singleton?
When the service is thread-safe and should be shared across the app’s lifetime, like a cache or configuration reader.
What’s the danger of using Singleton for DbContext?
DbContext isn’t thread-safe — using it as a singleton causes threading issues and shared-state bugs.
How do you register a service in .NET 9 DI?
builder.Services.AddScoped<IMyService, MyService>();
How does constructor injection work in .NET 9?
Dependencies are declared in a class constructor and automatically injected by the framework.
What should you do if an ASP.NET app doesn’t use DI?
Refactor direct new calls and static helpers into injectable services using interfaces and register them in DI.
How should static helper methods be handled during migration?
Move logic into classes implementing interfaces and register those in the DI container.
What replaces HttpModules and Global.asax event hooks in .NET 9?
Middleware in the Program.cs pipeline (e.g., app.UseRouting(), app.UseAuthentication()).
How is configuration handled differently in .NET 9?
.NET 9 uses appsettings.json and the IConfiguration API instead of web.config.
What CLI tool helps migrate old project files to SDK style?
try-convert
What routing system replaces RouteConfig.cs in .NET 9?
Endpoint Routing in Program.cs using app.MapControllers() or app.MapGet().
What’s a good first migration step if the app uses Web Forms?
Plan a rewrite using Razor Pages or MVC, since Web Forms aren’t supported in .NET 9.
What should you replace HttpContext.Current with?
Use constructor-injected IHttpContextAccessor.
Why is ASP.NET Core considered more testable?
Constructor injection and built-in DI make it easier to mock dependencies for unit testing.
What should you check when migrating third-party libraries?
Ensure they have .NET Standard or .NET 9-compatible packages on NuGet. Replace unsupported ones.
What’s a modern replacement for ASP.NET’s BundleConfig?
Use frontend tools like Webpack, or BundlerMinifier.Core for .NET projects.