Skip to content

Commit 173fb45

Browse files
authored
Merge pull request #256 from aspnetzero/pr/4615
Creates documentations for maui
2 parents 9fdd589 + 7e73f10 commit 173fb45

27 files changed

+976
-7
lines changed

docs/en/Developing-Step-By-Step-MAUI.md

+676
Large diffs are not rendered by default.

docs/en/Development-Guide-MAUI.md

+277
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
# MAUI Development Guide
2+
3+
## Introduction
4+
5+
MAUI is a cross-platform UI toolkit that allows developers to
6+
efficiently create native cross platform user interface layouts.
7+
This document is intended to show how to setup a MAUI development
8+
environment and introduce existing features and user interfaces on
9+
ASP.NET Zero MAUI platform. For an overview of the MAUI
10+
installation and setup practices see [MAUI Offical Documentation](https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation)
11+
For an overview of the ASP.NET Zero getting started see [ASP.NET Zero
12+
Getting Started.](Getting-Started-Core) The ASP.NET Zero MAUI is only
13+
available for ASP.NET Core included Angular UI and Mvc UI.
14+
15+
ASP.NET Zero uses Blazor version of MAUI with [Metronic](https://keenthemes.com/metronic) theme. Since it is a Blazor application, you can basically develop your application using html and css.
16+
17+
### Prerequisites
18+
19+
Following tools are needed in order to develop ASP.NET Zero MAUI:
20+
21+
- [Visual Studio 2022 17.3 ](https://www.visualstudio.com)+
22+
23+
### IOS
24+
25+
To build, sign, and deploy .NET MAUI apps for iOS, you'll also need:
26+
27+
- A Mac that is compatible with the latest version of Xcode. For more information, see Apple's minimum requirements documentation
28+
- The latest version of Xcode.
29+
- An Apple ID and paid Apple Developer Program enrollment. An Apple ID is required to deploy apps to devices, and to submit apps to the Apple Store.
30+
31+
### Solution Structure (Layers)
32+
33+
After [downloading](https://aspnetzero.com/Download) your project, you will see 3 types of solutions;
34+
35+
- **.Mobile** MAUI and related projects included.
36+
- **.Web** Web and related projects included.
37+
- **.All** All the projects included.
38+
39+
For MAUI development, you can open **.Mobile.sln**.
40+
41+
MAUI Architecture
42+
43+
<img src="images/maui-mobile-solution-overview.png" alt="ASP.NET Zero Mobile Solution" class="img-thumbnail" />
44+
45+
Mobile Solution
46+
47+
There are 4 projects in the mobile solution:
48+
49+
- **Core.Shared** project contains basic primitive types like consts,
50+
enums that used in all layers of the solution.
51+
- **Application.Shared** project contains data transfer objects (DTOs)
52+
and interfaces of application services shared with application layer
53+
of the backend.
54+
- **Application.Client** project contains Web Api client (bridge
55+
between mobile app and host) and proxy classes of Application
56+
Services.
57+
- **Mobile.MAUI** project contains mobile application.
58+
59+
MAUI app contains all platform specific files in the **Platforms** folder in project folder.
60+
<img src="images/maui-platform-spesific-items.png" alt="ASP.Net Zero platform specific files">
61+
62+
## Debugging
63+
64+
### Host
65+
66+
To start debugging MAUI app you need to configure host settings. You
67+
can use **Web.Host** to feed the MAUI app.
68+
Open Windows Command Prompt. Go to the folder where your **Web.Host csproj** file is located.
69+
Then run the command below to start hosting your Web API:
70+
71+
```bash
72+
dotnet run --launch-profile Mobile
73+
```
74+
75+
> This will start the Web.Host project from the address "https://0.0.0.0:44301" which enables to access it from external networks.
76+
77+
Alternatively, there's `start-host-mobile.bat` file in your **Web.Host** directory which does the same for Windows users.
78+
79+
**Warning**
80+
81+
If you want to start **Web.Host** from Visual Studio, set **Web.Host** as startup project and choose the `Mobile` profile.
82+
83+
![Host project](images/xamarin-mobile-profile-for-host.png)
84+
85+
86+
## Create a development certificate
87+
88+
Installing the .NET Core SDK installs the ASP.NET Core HTTPS development certificate to the local user certificate store. However, while the certificate has been installed, it's not trusted. To trust the certificate, perform the following one-time step to run the dotnet `dev-certs` tool:
89+
90+
```bash
91+
dotnet dev-certs https --trust
92+
```
93+
94+
This will allow to trust the self-signed ASP.NET Core HTTPS development certificate in your computer.
95+
96+
For more information, see [Connect to Local Web Services from iOS Simulators and Android Emulators]( https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services#create-a-development-certificate)
97+
98+
We have successfully started host. Now we can configure MAUI app to connect this host.
99+
100+
### Prepare for production
101+
102+
When you release your MAUI app for production you need to change **DefaultHostUrl** in **ApiUrlConfig** class!
103+
104+
```
105+
ApiUrlConfig.DefaultHostUrl = "https://mywebapi.com/"
106+
```
107+
108+
**Important**
109+
Be aware that connecting over Wi-Fi needs both the device and the computer to be on the same Wi-Fi network! To avoid confusions to you can completely turn off your mobile data connection.
110+
111+
<img src="images/xamarin-api-url-config.png" alt="Debug IP Address" class="img-thumbnail" />
112+
113+
### Debugging Android
114+
115+
There are a few installation steps and configuration details required to install `MAUI`. It's highly recommended you to read the [MAUI Android](https://learn.microsoft.com/en-us/dotnet/maui/android/emulator/hardware-acceleration) for necessary setups.
116+
117+
* If you are using the default Android Emulator, you don't need to change anything. The default loopback address for the Android emulator is `10.0.2.2` and it's written in the `StartApplication()` method of `MainLayout.razor.cs`
118+
119+
````csharp
120+
DebugServerIpAddresses.Current = "10.0.2.2";
121+
````
122+
123+
* If you are using [Genymotion Emulator](https://www.genymotion.com/), change it as below:
124+
125+
```csharp
126+
DebugServerIpAddresses.Current = "10.0.3.2"
127+
```
128+
129+
* If you are using a real Android device, change it as your computer's local IP and make sure your Android device and your computer is connecting from the same network (your local Wi-Fi). To connect your real mobile device, make sure your computer's firewall is off (or create an exception in your firewall to allow the port `44301`)
130+
131+
````bash
132+
DebugServerIpAddresses.Current = "XXX.XXX.XXX.XXX"
133+
````
134+
135+
After successful setup, set **Mobile.MAUI** as startup project. Choose an Android emulator from list and press start button.
136+
137+
<img src="images/maui-android-emulator-selection.png" alt="Android Emulator Selection" class="img-thumbnail" />
138+
139+
140+
### Debugging iOS
141+
142+
There are a few requirements that must be adhered to when developing for iOS in Visual Studio. A Mac, an IPAD or an IPhone is required to compile IPA files. Applications cannot be deployed to a device without Apple's certificates and code-signing tools. Also, the iOS simulator can be used only on a Mac.
143+
144+
You need to set DebugServerIpAddresses as your local IP. Eg: `192.168.1.120`
145+
146+
````bash
147+
DebugServerIpAddresses.Current = "XXX.XXX.XXX.XXX";
148+
````
149+
## Mobile.MAUI
150+
151+
### Folder struction
152+
153+
MAUI project has a very basic structure. ASP.NET Zero adds or modifies these files in the default project;
154+
155+
<img src="images/maui-project-struction.png" alt="Project Structure" class="img-thumbnail" />
156+
157+
Android Project Structure
158+
159+
- **Pages** This is where all pages located. You can add your pages in that folder. Pages added here will be used in Android and IOS.
160+
- **Platforms** This is where all platrform specific implemetations can be made. Every code written here is only published to the relevant platform.You can locate any platform specific codes in that folders. For example, If your service has platform based implementation, you can use that folder and implement it to DI container according to their platform.
161+
- **Resources** This is where application resources located.
162+
- **Services** This is where mobile based services implemented.
163+
- **Shared** This is where all blazor based shared items located. Layouts, base components, partial components are located in this folder.
164+
- **wwwroot** Since ASP.NET Zero uses Blazor version of MAUI, all web based items(index.html, css, js etc...) are located in this folder.
165+
166+
167+
#### Dependency Injection
168+
169+
ASP.NET Zero MAUI uses ASP.NET Boilerplate Framework's dependency
170+
injection system. Therefore it uses [Castle
171+
Windsor](http://www.castleproject.org/projects/windsor/) as an Inversion of Control container. To resolve dependencies; you can use constructor or property injection, beside there's a shortcut class called *DependencyResolver,* which can be used to resolve dependencies as well.
172+
ASP.NET Boilerplate provides *ITransientDependency* and
173+
*ISingletonDependency* interfaces as a shortcut to register classes. See [ASP.NET Boilerplate Dependency Injection](https://aspnetboilerplate.com/Pages/Documents/Dependency-Injection/)
174+
175+
#### Communicating with Host Api
176+
177+
***AbpApiClient*** class is used to communicate with host. In this
178+
class, *[FlurlClient](https://github.com/tmenier/Flurl)*  is used as http client. The host address *DefaultHostUrl* is stored in
179+
*ApiUrlConfig* class. Before publishing application you need to change
180+
this address with your production host server address. In development
181+
time, it's important to change *LocalhostIp* as your computer's LAN IP
182+
in *DebugServerIpAdresses.cs.*
183+
184+
***WebRequestExecuter*** class handles http web requests in a safe
185+
manner. When the request fails, it handles different types of
186+
exceptions. So if it's a timeout exception, it asks user to retry the
187+
same request. Or if it's a user friendly exception thrown by ABP it
188+
shows an alert and so on... You have to write a success and a fail
189+
callback to handle the result. In fail callback, the exception can be
190+
retrieved and in success callback result of the request can be
191+
retrieved.
192+
193+
***SetBusyAsync*** method is in the base class of components in
194+
*AbpZeroTemplateComponentBase* class. Whenever a long lasting operation is required
195+
it should be wrapped with SetBusyAsync method in view model so that user
196+
can see a busy indicator.
197+
198+
#### Exception Handling
199+
200+
All exceptions are globally handled in *ExceptionHandler* class,
201+
when you use *WebRequestExecuter*.
202+
203+
#### Pages
204+
205+
##### InitialView
206+
207+
InitialView is a transition page that checks whether user has any
208+
granted menu permission or not. If user has no permissions then an info
209+
message will be shown on the screen. But if user has at least one
210+
granted menu permission, it is automatically being navigated to the
211+
first authorized menu item.
212+
213+
##### Login
214+
215+
<img src="images/maui-login.png" alt="Login screen" class="img-thumbnail" />
216+
217+
When user enters credentials *AccessTokenManager* authenticates user,
218+
stores access token in memory. For authentication needed Api calls, this
219+
token is being added to the request as bearer token. There's a timer in
220+
*AccessTokenManager* class that renews token before it expires. If an
221+
error occurs while communicating with host, client tries to reconnect using refresh token
222+
within an exponentiation increasing time. After successful login user
223+
credentials are stored in device. User information is being set in
224+
*ApplicationContext* so if current logon account information is needed
225+
it can be retrieved with injecting *IApplicationContext*.
226+
227+
##### Menu
228+
229+
<img src="images/maui-menu.png" alt="Application menu" class="img-thumbnail" />
230+
231+
Menu items are stored in *MenuProvider* class. A menu item is shown if
232+
only user has granted required permission.
233+
234+
##### Tenants View
235+
236+
<img src="images/maui-tenant-page.png" alt="Tenants page" class="img-thumbnail" />
237+
238+
In this page you can see all tenants in your application. You can create new tenant, edit tenant or delete tenant. (If you have necessary permissions, otherwise you will not be able to see related buttons or page)
239+
There is a search bar on the top
240+
that filters tenants.
241+
You can _Create_ new tenant, _Edit_ or _Delete_ existing tenants using related button in the row. (If you dont have permission buttons will not be shown)
242+
243+
Create Tenant | Edit Tenant | Delete Tenant
244+
:-------------------------:|:-------------------------:|:-------------------------:
245+
<img src="images/maui-create-tenant.png" alt="Create Tenant" class="img-thumbnail" /> | <img src="images/maui-edit-tenant.png" alt="Edit Tenant" class="img-thumbnail" /> | <img src="images/maui-delete-tenant.png" alt="Delete Tenant" class="img-thumbnail" />
246+
247+
##### User View
248+
249+
<img src="images/maui-user-list.png" alt="Users page" class="img-thumbnail" />
250+
251+
This page lists users of the tenant or tenant owner. It is only shown if
252+
the user has permission to this page. Same as tenants view, there's a
253+
search bar and a new user creation toolbar item. hen a user is being tapped, it's navigated to edit user modal with the selected user.
254+
255+
You can create new user or manage existing one.
256+
257+
Create User | Edit User | Delete User
258+
:-------------------------:|:-------------------------:|:-------------------------:
259+
<img src="images/maui-create-user.png" alt="Create Tenant" class="img-thumbnail" /> | <img src="images/maui-edit-user.png" alt="Edit Tenant" class="img-thumbnail" /> | <img src="images/maui-delete-user.png" alt="Delete Tenant" class="img-thumbnail" />
260+
261+
## Distribution
262+
263+
### Configuration
264+
265+
- Before publishing the application change the **DefaultHostUrl** in
266+
**ApiUrlConfig** class. how to distribute MAUI application.
267+
- Change all application icon files with your own app icon.
268+
- Change all AppLogo.png files with your own app logo.
269+
- Version your application for future updates.
270+
271+
### Publishing
272+
273+
If you want to publish your application to the related application store
274+
you can read the MAUI official guides;
275+
276+
- [Publish a .NET MAUI app for Android](https://learn.microsoft.com/en-us/dotnet/maui/android/deployment/overview)
277+
- [Publish a .NET MAUI app for iOS](https://learn.microsoft.com/en-us/dotnet/maui/ios/deployment/overview)
Loading
21 KB
Loading
Loading

docs/en/images/maui-create-person.png

97.2 KB
Loading

docs/en/images/maui-create-tenant.png

111 KB
Loading

docs/en/images/maui-create-user.png

91.4 KB
Loading
86.7 KB
Loading

docs/en/images/maui-delete-tenant.png

80 KB
Loading

docs/en/images/maui-delete-user.png

131 KB
Loading

docs/en/images/maui-edit-person.png

93.1 KB
Loading

docs/en/images/maui-edit-tenant.png

86.8 KB
Loading

docs/en/images/maui-edit-user.png

147 KB
Loading

docs/en/images/maui-list-person.png

64.3 KB
Loading

docs/en/images/maui-login.png

20.4 KB
Loading

docs/en/images/maui-menu.png

122 KB
Loading
17.4 KB
Loading
Loading
Loading
51.1 KB
Loading
69.1 KB
Loading
16.5 KB
Loading

docs/en/images/maui-tenant-page.png

56.3 KB
Loading

docs/en/images/maui-user-list.png

80.5 KB
Loading

docs/en/nav-aspnet-core-angular.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,13 @@
275275
]
276276
},
277277
{
278-
"text": "Mobile (Xamarin)",
278+
"text": "Mobile",
279279
"path": "Xamarin.md",
280280
"items": [
281+
{
282+
"text": "MAUI Development Guide",
283+
"path": "Development-Guide-MAUI.md"
284+
},
281285
{
282286
"text": "Development Guide",
283287
"path": "Development-Guide-Xamarin.md"
@@ -478,10 +482,14 @@
478482
]
479483
},
480484
{
481-
"text": "Mobile (Xamarin)",
485+
"text": "Mobile",
482486
"items": [
483487
{
484-
"text": "Developing Step By Step",
488+
"text": "Developing Step By Step for MAUI",
489+
"path": "Developing-Step-By-Step-MAUI.md"
490+
},
491+
{
492+
"text": "Developing Step By Step for Xamarin",
485493
"path": "Developing-Step-By-Step-Xamarin.md"
486494
}
487495
]

docs/en/nav-aspnet-core-mvc.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,15 @@
265265
]
266266
},
267267
{
268-
"text": "Mobile (Xamarin)",
268+
"text": "Mobile",
269269
"path": "Xamarin.md",
270270
"items": [
271271
{
272-
"text": "Development Guide",
272+
"text": "MAUI Development Guide",
273+
"path": "Development-Guide-MAUI.md"
274+
},
275+
{
276+
"text": "Xamarin Development Guide",
273277
"path": "Development-Guide-Xamarin.md"
274278
}
275279
]
@@ -521,10 +525,14 @@
521525
]
522526
},
523527
{
524-
"text": "Mobile (Xamarin)",
528+
"text": "Mobile",
525529
"items": [
526530
{
527-
"text": "Developing Step By Step",
531+
"text": "Developing Step By Step for MAUI",
532+
"path": "Developing-Step-By-Step-MAUI.md"
533+
},
534+
{
535+
"text": "Developing Step By Step for Xamarin",
528536
"path": "Developing-Step-By-Step-Xamarin.md"
529537
}
530538
]

0 commit comments

Comments
 (0)