An instance of what type can be used to access environment variables and file locations in an ASP.NET Core app?
IWebHostEnvironment
What extension method of the HostEnvironmentEnvExtensions class returns true if the environment variable is set to Production (ASP.NET Core)?
IsProduction()
What type is used to create an instance of ILogger<T> in ASP.NET Core?
ILoggerFactory
What extension method of the HostEnvironmentEnvExtensions class returns true if the environment variable is set to Development (ASP.NET Core)?
IsDevelopment()
What are .NET console applications that create and configure a WebApplication (an instance of IHost)?
ASP.NET Core apps
What is the type that you call CreateBuilder on in a typical ASP.NET Core Program.cs?
WebApplication
What class in an ASP.NET Core app implements the IHostEnvironment interface and includes environment variables and file locations?
IWebHostEnvironment
What property of the IWebHostEnvironment in an ASP.NET Core app is set to the value of the ASPNETCORE_ENVIRONMENT environment variable?
EnvironmentName
What is the class in an ASP.NET Core app which has a property called EnvironmentName, usually with the value of ASPNETCORE_ENVIRONMENT?
EnvironmentName
What environment variable sets the value of the EnvironmentName property of IWebHostEnvironment?
ASPNETCORE_ENVIRONMENT
What type in an ASP.NET Core app is used to determine the runtime environment?
IWebHostEnvironment
What file usually sets the ASPNETCORE_ENVIRONMENT environment variable when developing the app?
launchSettings.json
What static class in ASP.NET Core supplies three environment names for you to use?
Environments
What class provides extension methods (isProduction(), isStaging(), etc.) on the IHostEnvironment for working with the EnvironmentName property?
HostEnvironmentEnvExtensions
ASP.NET Core apps are .NET console apps that create and configure a what?
WebApplication
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
//more code to be placed here later
}
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
What adds in support for using controllers and action methods?
AddControllers()
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
//more code to be placed here later
}
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
What creates the basic OpenAPI support?
AddSwaggerGen()
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
//more code to be placed here later
}
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
What compacts the most typical application setup into one method call (it configures the app using environment variables and JSON files, configures the default logging provider, and sets up the dependency injection container)?
CreateBuilder()
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
//more code to be placed here later
}
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
What type is used here to register services and do additional configuration after CreateBuilder() is called?
WebApplicationBuilder
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
//more code to be placed here later
}
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
What starts the app and gets everything ready to receive web requests and respond to them?
Run()
What would you use instead of AddControllers() (used for a RESTful service) in an MVC style ASP.NET Core app?
AddControllersWithViews();
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
What turns on HTTP Strict Transport Security?
UseHsts()
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
What enables static content (images, JavaScript files, CSS files, etc.) to be rendered through the application?
UseStaticFiles()
What mechanism that supports loose coupling between objects was one of the main tenets in the rewrite of ASP.NET Core?
Dependency injection
What are the three lifetime options that can be used when an item is configured into the ASP.NET Core dependency injection container?
Transient, Scoped, Singleton
What ASP.NET Core DI container lifetime option is "created each time they are needed"?
Transient
What ASP.NET Core DI container lifetime option is "created once for each request"?
Scoped
What ASP.NET Core DI container lifetime option is "created once on first request and then reused for the lifetime of the object"?
Singleton
What ASP.NET Core DI container lifetime option is recommended for Entity Framework DbContext objects?
Scoped
What type are services added into the DI container through (ASP.NET Core)?
IServiceCollection
What line is it important that you add services to the ASP.NET Core DI container before?
var app = builder.Build();
What method adds in the necessary services to support the MVC pattern in ASP.NET Core?
AddControllersWithView()
What do RESTful service web applications use instead of the AddControllersWithViews() method since they don't use views but do need controller support?
AddControllers()
What method that adds the DbContext into the DI container creates a pool of instances that are cleaned between requests (ensuring no data contamination)?
AddDbContextPool()
What attribute must be used in action methods to distinguish between a binding target and a service from the DI container?
FromServices
What class did ASP.NET Core 2.1 introduce that creates and configures HttpClient instances?
IHttpClientFactory
What are the options for web servers when deploying an ASP.NET Core app to Linux and not in a container?
Apache and Nginx
What does the Pro C# book call an example of a popular container-based deployment model?
Docker
What interface is logging in ASP.NET Core based on?
ILoggerFactory
What is the logging framework that can be used in ASP.NET Core that the Pro C# book covers?
Serilog
Previous card
First card
Random order
Next card