Assessments

Chapter 1

  1. What are the benefits of dependency injection?

It allows better separation of the interface and the actual implementation and lets us change the implementation at any time. It also recursively injects all required dependencies.

  1. What are environments?

A named set of startup values.

  1. What does MVC mean?

Easy peasy: model-view-controller!

  1. What are the supported lifetimes in the built-in dependency injection container?

Transient (a new instance is created every time), Scoped (a new instance is created on each HTTP request and always returned), and Singleton (a single instance is created).

  1. What is the difference between .NET Core and .NET Standard?

.NET Standard is just a standard set of APIs that is implemented by .NETand.NET Core, among others.

  1. What is a metapackage?

A set of packages, as defined by Microsoft. It contains all the packages that you will typically need for a simple ASP.NET Core project.

  1. What is OWIN?

OWIN stands for Open Web Interface for .NET, and you can read about it at http://owin.org. Essentially, it's a specification for decoupling a web application from a particular server, like IIS.

Chapter 2

  1. What is the root interface for retrieving configuration values?

It's IConfiguration. It's where IConfigurationRoot and IConfigurationSection inherit from.

  1. What are the built-in file-based configuration providers in .NET Core?

JSON, XML, and INI.

  1. Is it possible to bind configurations to POCO classes out of the box?

Yes, but we need to add the Microsoft.Extensions.Configuration.Binder NuGet package.

  1. What is the difference between the IOptions<T> and IOptionsSnapshot<T> interfaces?

IOptionsSnapshot<T> gets updated whenever the underlying configuration changes (if we configured it for that), but IOptions<T> always retains the original configured value.

  1. Do we need to register the configuration object explicitly in the dependency injection container?

No. As of ASP.NET Core 2.0, IConfiguration is injected automatically.

  1. How can we have optional configuration files?

When registering a file-based configuration file, set the optional parameter to true.

  1. Is it possible to get notifications whenever a configuration changes?

Yes. We need to get a reload token and then register in it a change callback delegate.

Chapter 3

  1. What are the special route tokens?

[controller], [action], and [area].

  1. How can we prevent a route from being selected depending on the request's HTTP verb?

Apply one of the[HttpPost],[HttpGet],[HttpPut],or other HTTP attributes to its action method.

  1. How can we prevent a route from being selected unless the request uses HTTPS?

Apply the [RequireHttps] attribute to the route's action method.

  1. How can we serve different views depending on the HTTP error code that occurred?

One way is to use eitherUseStatusCodePagesWithRedirectsor UseStatusCodePagesWithReExecuteinside theConfiguremethod of theStartupclass, create an action method on a controller that responds to the specific error code (for example,/error/401) by adding an[HttpGet("error/401")]attribute to it.

  1. How can we prevent methods in controllers from being called?

The best way is to apply a [NonAction] attribute to the methods that we want to hide.

  1. How can we force a route value to be of a particular type (for example, a number)?

Add the number validation token—for example, [HttpGet("{id:number]")].

  1. What is a route handler?

It's the implementation of the IRouter interface that actually processes the request. For MVC, it is normally the MvcRouteHandler class, which is added to the pipeline by the UseMvc extension method.

Chapter 4

  1. What is the default validation provider for the model state?

It is the Data Annotations API.

  1. What is an action?

A method that can be called on a controller in response to an HTTP request.

  1. What is globalization and how does it differ from localization?

Globalization means your application will support multiple cultures. Localization is the process of making your application work and react accordingly to a specific culture.

  1. What is temporary data used for?

Temporary data is used to persist data between two subsequent requests for the same client, like a micro-session.

  1. What is a cache good for?

A cache is useful for data that either takes a long time to produce or to retrieve. We store such data in the cache and can quickly access it.

  1. What is a session?

A session is a group of user interactions with a website that takes place within a given time frame. Each interaction is associated with the session by means of session ID.

  1. What are the benefits of a controller inheriting from the Controller base class?

The Controller class offers some useful methods that are not present in ControllerBase, such as methods to return views (View).

Chapter 5

  1. What is the base class for a view?

It's RazorPage<T>, where the T generic type is dynamic by default.

  1. How can you inject services into a view?

Either by using the @inject declaration on a .cshtml file or by inheriting from the RazorPage<T> class and using constructor injection.

  1. What is a view location expander?

It's a component that can be used to tell ASP.NET Core where to look for the physical .cshtml files.

  1. What is a view layout?

It is similar to master pages in ASP.NET Classic. Essentially, it defines the layout, or structure, that different pages can use.

  1. What are partial views?

Partial views are similar to web user controls (.ascx files) in ASP.NET Classic. They are files containing reusable markup and possibly code that is meant to be reused across different views.

  1. What functionality can replace partial views?

View components.

  1. What does the special file _ViewStart.cshtmldo?

Whatever code, @using, or @inject declarations you put in it is executed before the actual view.

Chapter 6

  1. What is the default validation provider?

It's the data annotations validator.

  1. What do we call the methods that are used to render HTML fields?

HTML helpers.

  1. What is model metadata?

It's the code that describes what a model's properties are, such as their display name, whether or not they are required, what validation should they use, and so on.

  1. Does ASP.NET Core support client-side validation?

Yes, it does.

  1. What is the base interface that can be bound to an uploaded file?

IFormFile.

  1. What is unobtrusive validation?

It's the process by which adding a couple of JavaScript libraries automatically sets up validation, based on some conventions.

  1. How can we perform server-side validation?

By leveraging the [Remote] attribute and implementing a validation action method on a controller.

Chapter 7

  1. What attribute can we use to mark a method or controller so that it can only be called through HTTPS?

[RequireHttps].

  1. What is the difference between role-based and policy-based authorization?

Policy-based authorization is more powerful; it can use both roles or any other custom requirement that you can think of.

  1. What is the purpose of CORS?

CORS is a mechanism by which servers can tell the browsers to bypass their normal security restrictions and allow the loading of static resources (normally scripts) from different sources (servers).

  1. What is the purpose of HSTS?

It is a web policy for telling the browsers that they should only interact with a server through HTTPS. It is specified in RFC 6797.

  1. What is the challenge stage of the authentication process?

The challenge is when the server asks the client for valid credentials.

  1. Why should we take care when binding requests to model classes?

We do not want sensitive information that should not be provided by the client to be bound to the model.

  1. What is the sliding expiration of a cookie?

It means that on each request, the cookie is renewed for the same amount of time that it was initially set to.

Chapter 8

  1. What is OData?

OData is an open protocol for exposing and consuming queryable RESTful data models.

  1. What is content negotiation?

It is a process by which the client and the server agree on the type of content that is to be returned.

  1. Why is it not suitable to use cookies for authentication in web APIs?

Because usually the client for these APIs will not be a web browser, and therefore may not have the capacity to store cookies.

  1. What are the different ways by which we can ask for a specific version of our API?

The query string or an HTTP header.

  1. What is the purpose of conventions in regard to action methods?

A convention allows us to define the return type and HTTP status code that is returned from each action method, and any exceptions that may arise.

  1. What are problem details?

A way to return error information in a standard way. Problem details are defined in RFC 7807.

  1. What is REST?

An architectural style for defining web services, designed for interoperability, that relies on HTTP verbs, URLs, and headers.

Chapter 9

  1. How can we load partial views from a different assembly?

By using embedded resources, or better, Razor class libraries.

  1. What are the two ways to render partial views?

One is to use the Html.PartialAsync method and the other is to use the <partial> tag helper.

  1. What is the difference between tag helpers and tag helper components?

Tag helpers render a component instead of a custom or an HTML tag, and a tag helper component allows us to intercept and possibly modify all HTML tags before they are rendered.

  1. How can we restrict what is displayed on a view depending on the environment?

By using the <environment> tag helper.

  1. What is the difference between Razor class libraries and class libraries?

Razor class libraries allow us to make static resources available to web projects very easily, whereas class libraries are only about code.

  1. What are embedded resources?

Static files (images, text, and others) that are included inside assemblies and can be retrieved from them.

  1. What are the two syntaxes for executing view components?

One is the code syntax—Component.InvokeAsync("mycomponent", new { arg1 = "...", arg2 = 123 })—and the other is markup—<mycomponent arg1="..." arg2="123"/>.

Chapter 10

  1. What are the two interfaces that are used to control authorization to a resource?

IAuthorizationFilter and IAsyncAuthorizationFilter.

  1. Why are there two versions of each kind of filter?

There is always an asynchronous version, which should probably be preferred.

  1. How can we apply a filter by specifying its type on an action method?

Either through the ServiceFilterAttribute or TypeFilterAttribute.

  1. How can we apply an ordering to the application of filters?

When applying a filter using attributes, we can use the Order property.

  1. What are the different levels to which we can apply filters?

Global, controller, and action method.

  1. How can we pass context from one filter to others?

Using the HttpContext.Items collection.

  1. How can filters make use of dependency injection?

The [ServiceFilter] can obtain filters from DI depending on their type.

Chapter 11

  1. Do Razor Pages use code-behind?

Yes, they can, but it is not mandatory. The code-behind class must inherit from PageModel and be located together with the .cshtml file.

  1. What is the purpose of the Page Model?

It is where the handlers for the different HTTP verbs (GET, POST, and so on) are implemented.

  1. What are page handlers?

They are the code that processes the requests inside a PageModel class.

  1. How can we restrict a Razor Page from being called by anonymous users?

We add a convention using the AllowAnonymousToPage extension method when configuring Razor Page options with the AddRazorPagesOptions method, following AddMvc.

  1. What are the two ways by which we can inject services into a Razor Page?

One way is to use constructor injection on the PageModel class and the other is by using the @inject directive on the .cshtml file.

  1. Do Razor Pages use page layouts?

Yes—just make sure you keep them separated from the other view layouts.

  1. Where are Razor Pages served by default?

The Pages folder.

Chapter 12

  1. What are event counters?

Lightweight code that is emitted by the applications and picked up by the operating system.

  1. What is the benefit of telemetry?

To centralize the storing of logs and events and monitor applications from a single dashboard.

  1. How can we filter logging?

By category name or log level.

  1. What are health checks?

They indicate how well our application or dependencies (for example, databases, external services, and so on) are.

  1. How is middleware useful in logging?

It can sit in the middle of the request and log before and after the request is processed.

  1. What is ELM?

Error logging middleware—it is used to view events raised during the processing of a request.

  1. What are the benefits of diagnostics over common logging?

Diagnostics offers strong typed events and integration with ELM for the easy viewing of events.

Chapter 13

  1. What are the more popular unit test frameworks?

NUnit, xUnit, and MSTest.

  1. What is the benefit of mocking?

Substituting dependencies.

  1. What is the difference between unit and integration testing?

A unit test should be fast, not have any side effects, and should only test a specific operation, whereas an integration test works on a much bigger scale.

  1. What is TDD?

Test-driven development: a methodology that advocates starting with the unit tests.

  1. What are the limitations of unit tests?

They usually do not test aspects such as user interfaces or database operations.

  1. How can we pass data automatically to unit tests?

All of the studied unit test frameworks allow the passing of data from attributes to test methods.

  1. What does red-green-refactor mean?

It's a practice of TDD where we start by writing the tests, which initially fail (red), then we make them pass (green), and only then should we worry about refactoring the code so as to make it more efficient.

Chapter 14

  1. What are the benefits of TypeScript?

It has strong typing and is a full object-oriented programming model.

  1. Does JavaScript only run on browsers?

No—it can also run on the server side.

  1. What are SPAs?

Single-page applications, applications based on JavaScript that call server-side functionality through AJAX-style calls.

  1. What is the purpose of Library Manager?

To install client-side libraries in local projects.

  1. Are the templates for dotnet SPA frameworks hardcoded?

No—they are available as NuGet packages, and can be installed and updated.

  1. How can we run JavaScript code from .NET Core?

NodeServices provides this functionality.

  1. Name a few SPA frameworks that have dotnet templates.

Vue, React, Angular, Aurelia, and Knockout.

Chapter 15

  1. What are the two hosts available to ASP.NET Core 3?

Kestrel and HTTP.sys.

  1. What are the two kinds of cache that are available?

In-memory and distributed.

  1. What is the benefit of compressing a response?

Minimizing the latency of the response.

  1. What is the purpose of caching a response?

Avoiding the need to request and send responses.

  1. Do asynchronous actions improve performance?

No, but they improve scalability.

  1. What is bundling?

Bundling is the combining of multiple files in a single response.

  1. What are profilers good for?

They can show us what parts of our code are taking the most time to execute.

Chapter 16

  1. What are the two serialization formatters supported by SignalR?

JSON and Message Pack.

  1. What transports does SignalR support?

AJAX long polling, WebSockets, and server-sent events.

  1. What are the benefits of the Message Pack protocol?

Message Pack is more compact, thereby resulting in lower latency.

  1. Which targets can we send messages to?

Single recipient, all users, or groups of users.

  1. Why would we restrict the transport to be used by SignalR?

Some transports might not be supported or might be restricted—for example, WebSockets.

  1. Can we send messages to SignalR from outside the web application where it is hosted?

Yes.

  1. Can we use authentication with SignalR?

Yes.

Chapter 17

  1. What is the difference between a page and a component?

The only difference between the two is that pages can be directly accessed from the browser.

  1. What is the difference between the Server and WebAssembly hosting models?

The Server model relies on SignalR to communicate to and from the server, whereas WebAssembly lives only on the client that is being compiled to webassembly, hence the name. WebAssembly can work while disconnected.

  1. Can we use tag helpers in Blazor pages?

No, we can't (in .razor files).

  1. Is it possible to access the containing web page from inside Blazor?

Yes, it is, using JavaScript interoperability.

  1. Does Blazor support dependency injection?

Yes, it does, but not constructor injection.

  1. Do Blazor page layouts support regions?

Yes, but only a single region—body.

  1. What is the difference between the different rendering modes of a component?

The difference lies in performance and capacities: Static is fastest, but does not support server events, Server is the slowest and cannot take parameters, and ServerPrerendered is a tradeoff between the two—a part of the component is prerendered, but the actual interaction only starts when the page fully loads.

Chapter 18

  1. What is gRPC?

gRPC is Google Remote Procedure Call, a cross-platform technology for implementing web services that are agnostic regarding the technology.

  1. What is the purpose of URL rewriting?

Presenting user-friendly URLs that will be translated to something meaningful to the application.

  1. What are background services useful for?

Running tasks on the background.

  1. What is the purpose of areas?

Physically and conceptually separating parts of the application.

  1. What are conventions good for?

Automatically enforcing defaults.

  1. How can we execute code from a referenced assembly automatically?

By adding a [HostingStartup] attribute to a library and by including it in the ASPNETCORE_HOSTINGSTARTUPASSEMBLIES environment variable.

  1. Can we load files from inside assemblies?

Yes—either as embedded resources or from Razor class libraries.

Chapter 19

  1. What are the advantages of using IIS for exposing your app to the outside?

You can add logging and Windows authentication, for example.

  1. Why would you host your web app as a Windows Service?

It makes it easier to start and stop and to see whether the service is running.

  1. What is the advantage of using Docker?

You can accurately control the dependencies and the running environment.

  1. What is a self-contained deployment?

It is a deployment that does not require .NET Core to be installed on the target machine.

  1. Is it possible to detect changes and recompile the code automatically at runtime?

Yes—we just need to run the dotnet watch command.

  1. Can we deploy using the command line or do we need Visual Studio?

We can use both the command line (dotnet) or Visual Studio.

  1. To what cloud providers can you deploy from inside Visual Studio?

Azure and AWS are two examples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.227.69