Designing and Architecting Blazor Applications Flashcards
(31 cards)
Why Blazor instead of the well known javascript frameworks?
Written in c# and razor syntax.
Can leverage existing .net standard nuget packages.
Powerfull tooling.
Fully supported by Microsoft.
Blazor also is likelly to be faster than JS due the fact it runs over web assembly.
What does it mean saying that Blazor is make in a “component driven design”?
It means the pages are built using different components. Reusable components.
What are the main benefits of Blazor?
Depenendy Injection, Hosting Options, Standarized Packages, Javascript Interop.
What is the role of a service in a MVC project?
It sits between the controller and the repository. Useful when some business logic is necessary.
When to use parameter dependency injection and when to use constructor dependency injection?
Parameter dependency injection is used for components and the constructor (most common) dependency injection is used for services.
How to inject a logger into a blazor component?
By simply add a inject parameter of the type ILogger
What is a Blazor circuit?
Is the context of a connection of a user/tab to our blazor server (not applicable to Blazor web assembly).
What is a scoped service lifecycle?
It means the same instance of the service will be used along in the same Blazor circuit (aka context)
What is a blazor route constraint?
It allows enforcing a specific param type to a route.
How can we monitor page changes in the blazor app?
With the LocationChanged event from the RouteManager class
What is a razor class library?
Allows creating and consuming common components to achieve re-usability. Can be published as a nuget package.
Only UI components can be packed in razor class lib ?
No… also functional libs can be packed into razor comps.
How to create a nuget package out of a razor class lib?
By simply selecting “Pack” in visual studio.
How to manage user’s state in the app (e.g: grid preferences)?
By using local or session storage.
What is the local storage?
It is owned by the browser and it stores all the tabs… non-secure data… good for keeping user preferences like hidden notifications and etc.
What is the session storage?
more secure… prevents data be loaded by a different user. scoped to the opened tab, then auto deleted.
Are local and session storage truly secure?
No. data is still somehow accessible - mitigated by encryption, but still need to be careful.
What is the recommended way to interact with the browser storage?
ProtectedBrowserStorage nuget package.. is still on Alpha. Need to change the host.cshtml to RenderMode.Server and add the js from the nuget package.
what is a common automatically generated API documentation?
swashbuckle swagger.
What is the correct way of using a HTTPClient in .net core? When was it introduced?
Via HTTPClientFactory. Introduced on .net 2.1
How http client can be used?
By typed HTTP clients and client factory directly.
how to instantiate a typed http client?
It looks more complicated that it is… all it is needed is a generic Timplementation of tclient… can be done using a simple anonymous method.
Does Blazor has its own http client lib?
Yes… it simplifies the unmarshalling.
what to do when the api expects key value pairs instead of a json (used to be like this in forms)?
Define a dictionary of the fields, then use link to create a url encoded string. then do the send async.