Me, myself and I playing around and continusouly learning with Blazor tid bits... for the love of learning and building kickass stuff with .NET platform! ;)
Project /BlazorClientApp
- Splitting Counter.razor file with the Counter.razor.cs code behind implementation.
public class CounterBase : ComponentBase
{
[Parameter]
public int CurrentCount { get; set; } = 0;
public void IncrementCount(){ ... }
}
- Extending from ComponentBase and inherited
@inherits CounterBase
into Counter.razor page - Added Counter.razor as a Component into the Index.razor page
- Switched from
HttpClient.GetFromJsonAsync()
toHttpClient.GetAsync()
with the use of System.Text.Json.JsonSerializer - Blazor Client renders content in Client's Web Browser
- Blazor Client Apps = Blazor WebAssembly Apps
- Blazor Client Apps cannot directly debug in Visual Studio
Project /BlazorTodoApp
- In-Memory todo list created in Todo.razor page
- Adding the Navigation path in NavMenu.razor
- Data binding with
@bind="newTodo"
across web UI elements - Adding Bootstrap css decorations for the elements
https://www.youtube.com/watch?v=CaxR4_fP-FA
Project /BlazorPersonApp
- ASP.NET Hosted Blazor Client App solution was created.
- Added a
PersonController
API endpoint in the BlazorPersonApp.Server project - Implemented Get and Post endpoints in the PersonController and implemented calls to pull data for the Client App
https://www.youtube.com/watch?v=8DNgdphLvag
Project /BlazorServerApp
- You can mix and mingle ASP.NET Core UI Components and Bootstrap Css Style
...
<InputText class="form-control" placeholder="First Name"
id="firstName" @bind-Value="_newPerson.FirstName" />
...
- Using
EditForm
Component withDataAnnotationsValidator
for validating data model
<EditForm class="form-group" Model="@_newPerson" OnValidSubmit="InsertPerson">
<DataAnnotationsValidator />
<ValidationSummary />
...
<EditForm>
- Make sure to create a local Database and set up the following table
CREATE TABLE [dbo].[People] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[FirstName] VARCHAR (50) NULL,
[LastName] VARCHAR (50) NULL,
[DateOfBirth] DATETIME NULL,
[EmailAddress] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
- Blazor Server renders content in Server, and uses SignalR WebSockets to transfer data back and forth
- Blazor Server Apps can directly debug in Visual Studio
- How to identify Blazor Server project? in the Startup.cs look for
services.AddServerSideBlazor();
https://www.youtube.com/watch?v=JE0tQ4tx0Nc
Project /BlazorComponentsApp
- Created the simple TaskList Component and reused it multiple times in a single page
- You can use multiple Components in a single page
- You can also Nest components within each other
- Remove
@page "/TaskList"
so it can't be used as a page
https://github.com/dotnet-presentations/blazor-workshop/
Project /BlazingPizzaApp
- The most comprehensive end to end blazor self learning experience ever!
- Its better to build Page UIs with separate Components put together.
NavigationManager
allows you to programmatically Navigate in your Blazor app.- Save the state of a page in the DI container
builder.Services.AddScoped<OrderState>();
- Saving the state will help you retain data during page navigation
- Using Annotations on the data model you can easily implement Server side data validation
- Using
EditForm
, you implement client side data validation - A nicer way to display input data field validation is by using
ValidationMessage
. [Authorize]
on the API Controller, to enforce Authorization for all incoming calls.- To enable the authentication services, for your Blazor Client add a call to
AddApiAuthorization
in Program.cs RemoteAuthenticatorView
component orchestrates the authentication flow.CascadingAuthenticationState
wraps to let you inherit auth state to child elements.AuthorizeView
will let you control displaying of elements based on auth state.- Use the
IAccessTokenProvider
injected to the pages for aquire AccessTokens. AuthenticationStateTask
lets you check programmatically if the user is logged in or not.AuthorizeRouteView
controls the direct access to routes based on auth state- Redirecting will make you lose state, but you can preserve it by implementing
RemoteAuthenticationState
. - Inject
IJSRuntime
to invoke JavaScript functions withJSRuntime.InvokeVoidAsync()
method. - Build Templated Components to increase the reusability of Components.
- Easily set up PWA features (installable, offline, push notifications) for Blazor, with
service-worker.js
configuration. - Use
WebPush
to set up Push Notifications in your Blazor application and Server backend. - Displaying and handling the received Push Notification is set up in
service-worker.js
. - To Publish to Azure, you need to create an
App Service
andHosting Plan
of Basic tier or higher. - Finally you need to set up a signing key with
Azure Key Vault
for the IdentityServer.