title
stringlengths 3
46
| content
stringlengths 0
1.6k
|
---|---|
19:920
|
.NET MAUI is not installed by default when you install Visual Studio 2022, but you need to select the .NET MAUI workload in the Visual Studio installer. Therefore, if you don’t see MAUI projects when you start a new project in your Visual Studio installation, you need to run the Visual Studio installer and modify your existing installation with the addition of the .NET MAUI workload.
|
19:921
|
Once you have the MAUI workload installed, in the project creation wizard, you should be able to select C#/All platforms/MAUI, and then select .NET MAUI Blazor Hybrid App, as shown here:
|
19:922
| |
19:923
|
Figure 19.3: Creating a .NET MAUI Blazor application
|
19:924
|
Create a MAUI Blazor project and call it MAUIBlazorReview. The MAUI Blazor application contains the usual Layout and Pages folders where you can place your Blazor components and pages, but they are placed inside a Components folder. It also contains a wwwroot folder containing the usual index.html page and all the CSS and JavaScript you might need. Finally, it also contains the usual _Imports.razor page where you can place all your default using statements.
|
19:925
|
A MAUI Blazor application also uses layout pages that you can place in the Shared folder and may reference Razor libraries containing CSS components and JavaScript files.
|
19:926
| |
19:927
|
Figure 19.4: .NET MAUI Blazor project
|
19:928
|
The only difference is that services, instead of being declared in Program.cs files, are declared in MauiProgram.cs together with MAUI-specific code:
|
19:929
|
public static class MauiProgram
|
19:930
|
{
|
19:931
|
public static MauiApp CreateMauiApp()
|
19:932
|
{
|
19:933
|
var builder = MauiApp.CreateBuilder();
|
19:934
|
builder
|
19:935
|
.UseMauiApp<App>()
|
19:936
|
.ConfigureFonts(fonts =>
|
19:937
|
{
|
19:938
|
fonts.AddFont(`OpenSans-Regular.ttf`, `OpenSansRegular`);
|
19:939
|
});
|
19:940
|
builder.Services.AddMauiBlazorWebView();
|
19:941
|
#if DEBUG
|
19:942
|
builder.Services.AddBlazorWebViewDeveloperTools();
|
19:943
|
builder.Logging.AddDebug();
|
19:944
|
#endif
|
19:945
|
//this is a service
|
19:946
|
builder.Services.AddSingleton<WeatherForecastService>();
|
19:947
|
return builder.Build();
|
19:948
|
}
|
19:949
|
}
|
19:950
| |
19:951
|
Attention must be paid when using an HttpClient class to communicate with a server. Blazor web applications may use URLs relative to the domain where they were downloaded, while MAUI Blazor applications must use absolute URLs since they are not associated with any default URL. Therefore, an HttpClient definition is added to the services with something like this:
|
19:952
|
builder.Services.AddScoped(sp => new HttpClient
|
19:953
|
{ BaseAddress = new Uri(`https://localhost:7215`) });
|
19:954
| |
19:955
|
The Platforms folder contains a subfolder for each platform supported by the application, where each subfolder contains platform-specific code.
|
19:956
| |
19:957
|
Figure 19.5: Platforms folder
|
19:958
|
Supported folders can be changed by editing the TargetFrameworks element of the MAUIBlazorReview.csproj file:
|
19:959
|
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
|
19:960
| |
19:961
|
You can select the platform to run the application from using the dropdown next to the green Visual Studio run button. On a Windows machine, you can select just Windows and Android. If you select Android, an Android device simulator is launched.
|
19:962
|
In order to debug for iOS/Mac platforms on a Windows machine, you need to connect an iOS/Mac device to your computer.
|
19:963
|
When you build the project, the build may ask you to install an Android SDK version. If this is the case, please follow the simple instructions in the error message.
|
19:964
|
Summary
|
19:965
|
In this chapter, you learned about client-side technologies. In particular, you learned what an SPA is and how to build one based on the Blazor WebAssembly framework. The chapter first described the Blazor WebAssembly architecture, and then explained how to exchange input/output with Blazor components and the concept of binding.
|
19:966
|
After having explained Blazor’s general principles, the chapter focused on how to get user input while providing the user with adequate feedback and visual clues in the event of errors. Then, the chapter provided a short description of advanced features, such as JavaScript interoperability, globalization, authentication with authorization, and client-server communication.
|
19:967
|
Finally, the last section explained how to use Blazor to implement cross-platform applications based on Microsoft MAUI and how to transform a Blazor WebAssembly project into a .NET MAUI Blazor project.
|
19:968
|
Complete examples of Blazor applications based on the WWTravelClub book use case can be found in the Using client technologies section of Chapter 21, Case Study.
|
19:969
|
Questions
|
19:970
| |
19:971
|
What is WebAssembly?
|
19:972
|
What is an SPA?
|
19:973
|
What is the purpose of the Blazor router component?
|
19:974
|
What is a Blazor page?
|
19:975
|
What is the purpose of the @namespace directive?
|
19:976
|
What is an EditContext?
|
19:977
|
What is the right place to initialize a component?
|
19:978
|
What is the right place to process the user input?
|
19:979
|
What is the IJSRuntime interface?
|
19:980
|
What is the purpose of @ref?
|
19:981
| |
19:982
|
Further reading
|
19:983
| |
19:984
|
The Blazor official documentation is available at https://docs.microsoft.com/en-us/aspnet/core/blazor.
|
19:985
|
Lazy loading assemblies is described at https://docs.microsoft.com/en-US/aspnet/core/blazor/webassembly-lazy-load-assemblies.
|
19:986
|
All HTML events supported by Blazor together with their event arguments are listed at https://docs.microsoft.com/en-us/aspnet/core/blazor/components/event-handling#event-arguments-1.
|
19:987
|
Blazor supports the same validation attributes as ASP.NET MVC, with the exception of RemoteAttribute: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation#built-in-attributes.
|
19:988
|
A description of the InputFile component, and how to use it, can be found here: https://docs.microsoft.com/en-US/aspnet/core/blazor/file-uploads.
|
19:989
|
More details on Blazor localization and globalization are available here: https://docs.microsoft.com/en-US/aspnet/core/blazor/globalization-localization.
|
19:990
|
More details on Blazor authentication and all its related URLs are available here: https://docs.microsoft.com/en-US/aspnet/core/blazor/security/webassembly/.
|
19:991
|
The Blazorise project: https://github.com/stsrki/Blazorise.
|
19:992
|
BlazorStrap: https://github.com/chanan/BlazorStrap.
|
19:993
|
Blazor Controls Toolkit: https://blazorct.azurewebsites.net/.
|
19:994
|
bUnit: https://github.com/egil/bUnit.
|
19:995
|
The Awesome Blazor project: https://github.com/AdrienTorris/awesome-blazor.
|
19:996
| |
19:997
|
Learn more on Discord
|
19:998
|
To join the Discord community for this book – where you can share feedback, ask questions to the authors, and learn about new releases – follow the QR code below:
|
19:999
|
https://packt.link/SoftwareArchitectureCSharp12Dotnet8
|
19:1000
| |
19:1001
| |
19:1002
| |
10:1
|
Deciding on the Best Cloud-Based Solution
|
10:2
|
When designing your application to make it cloud-based, you must understand different architectural designs – from the simplest to the most sophisticated. In fact, cloud technology not only enables cost optimization but also significantly reduces the time it takes to launch your solution to the market. Also, it effectively enhances your application’s ability to tolerate faults and scale. However, optimizing for cost, speed, resilience, and scalability often involves trade-offs in terms of constraints and flexibility, so you must choose the right compromise for your needs.
|
10:3
|
This chapter discusses different software architecture models and teaches you how to take advantage of the opportunities offered by the cloud in your solutions. This chapter will also discuss the different types of cloud service that we can consider while developing our infrastructure, what the ideal scenarios are, and where we can use each of them.
|
10:4
|
The following topics will be covered in this chapter:
|
10:5
| |
10:6
|
Infrastructure as a Service solutions
|
10:7
|
Platform as a Service solutions
|
10:8
|
Software as a Service solutions
|
10:9
|
Serverless solutions
|
10:10
|
How to use hybrid solutions and why they are so useful
|
10:11
| |
10:12
|
It is worth mentioning that the choice to be made between these options depends on different aspects of the project scenario, such as the need for flexibility and/or highly customized solutions versus simplicity, low maintenance costs, and low time-to-market. These trade-offs will be discussed throughout the whole chapter.
|
10:13
|
Technical requirements
|
10:14
|
For the practical content in this chapter, you must create or use an Azure account. We can find the detailed procedure for creating an Azure account in Chapter 1, Understanding the Importance of Software Architecture, in the Creating an Azure account section.
|
10:15
|
Different software deployment models
|
10:16
|
Let’s begin our exploration with Infrastructure as a Service (IaaS), the foundational layer of cloud computing. IaaS offers a flexible and scalable infrastructure, which is crucial for businesses with specific hardware requirements or those transitioning from on-premises solutions to the cloud.
|
10:17
|
In companies where you have infrastructure engineers, you will probably find more people working with IaaS. On the other hand, in companies where IT is not the core business, you will find a bunch of Software as a Service (SaaS) systems. It is common for developers to decide to use the Platform as a Service (PaaS) option or to go serverless, as they have no need to deliver infrastructures in this scenario.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.