From e3eea317af29fd0811ae251e45cc20369c7dce33 Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Tue, 17 May 2022 13:41:10 +0300 Subject: [PATCH 1/7] Create Quick Start Documentation for `app-nolayers` template --- docs/en/Tutorials/Todo/Single-Layer/Index.md | 347 +++++++++++++++++++ 1 file changed, 347 insertions(+) create mode 100644 docs/en/Tutorials/Todo/Single-Layer/Index.md diff --git a/docs/en/Tutorials/Todo/Single-Layer/Index.md b/docs/en/Tutorials/Todo/Single-Layer/Index.md new file mode 100644 index 0000000000..fe70013e19 --- /dev/null +++ b/docs/en/Tutorials/Todo/Single-Layer/Index.md @@ -0,0 +1,347 @@ +# Quick Start + +````json +//[doc-params] +{ + "UI": ["MVC", "BlazorServer", "NG"], + "DB": ["EF", "Mongo"] +} +```` + +This is a single-part quick-start tutorial to build a simple todo application with the ABP Framework. Here's a screenshot from the final application: + +![todo-list](../todo-list.png) + +You can find the source code of the completed application [here](TODO: sample's url???). + +## Pre-Requirements + +* An IDE (e.g. [Visual Studio](https://visualstudio.microsoft.com/vs/)) that supports [.NET 6.0+](https://dotnet.microsoft.com/download/dotnet) development. + +{{if DB=="Mongo"}} + +* [MongoDB Server 4.0+](https://docs.mongodb.com/manual/administration/install-community/) + +{{end}} + +{{if UI=="NG"}} + +* [Node v14.x](https://nodejs.org/) + +{{end}} + +## Creating a New Solution + +In this tutorial, we will use the [ABP CLI](../../CLI.md) to create the sample application with the ABP Framework. You can run the following command in a command-line terminal to install the **ABP CLI**, if you haven't installed it yet: + +````bash +dotnet tool install -g Volo.Abp.Cli +```` + +Then create an empty folder, open a command-line terminal and execute the following command in the terminal: + +````bash +abp new TodoApp -t app-nolayers{{if UI=="BlazorServer"}} -u blazor-server{{else if UI=="NG"}} -u angular{{end}}{{if DB=="Mongo"}} -d mongodb{{end}} +```` + +{{if UI=="NG"}} + +This will create a new solution with a single-project, named *TodoApp* with `angular` and `aspnet-core` folders. Once the solution is ready, open the solution in your favorite IDE. + +{{else}} + +This will create a new solution with a single-project, named *TodoApp*. Once the solution is ready, open it in your favorite IDE. + +{{end}} + +### Create the Database + +You can run the following command in the directory of your project to create the database and seed the initial data: + +```bash +dotnet run --migrate-database +``` + +This command will create the database and seed the initial data for you. Then you can run the application. + +### Run the Application + +{{if UI=="MVC" || UI=="BlazorServer"}} + +It is good to run the application before starting the development. Running the application is pretty straigth-forward, you can run the application with any IDE that supports .NET or by running the `dotnet run` CLI command in the directory of your project to see the initial UI: + +{{else if UI=="NG"}} + +It is good to run the application before starting the development. The solution has two main applications: + +* `TodoApp` (in the .NET solution) host the server-side HTTP API, so Angular application can consume it. (server-side application) +* `angular` folder contains the Angular application. (client-side application) + +Firstly, run the `TodoApp` project in your favorite IDE (or run the `dotnet run` CLI command on your project directory) to see the server-side HTTP API on the [Swagger UI](https://swagger.io/tools/swagger-ui/): + +![todo-swagger-ui-initial](../todo-swagger-ui-initial.png) + +You can explore and test your HTTP API with this UI. If it works, we can run the Angular client application. + +First, run the following command (or `yarn install`) to restore the NPM packages: + +````bash +npm install +```` + +It will take some time to install all packages. Then you can run the application using the following (or `yarn start`) command: + +````bash +npm start +```` + +This command takes time, but eventually runs and opens the application in your default browser: + +{{end}} + +![todo-ui-initial](../todo-ui-initial.png) + +You can click on the *Login* button, use `admin` as the username and `1q2w3E*` as the password to login to the application. + +All ready. We can start coding! + +## Defining Entities + +This application will have a single [entity](../../../Entities.md) and we can start by creating it. So, create a new `TodoItem` class under the **Entities** folder of the project. + +````csharp +using Volo.Abp.Domain.Entities; + +namespace TodoApp.Entities; + +public class TodoItem : BasicAggregateRoot +{ + public string Text { get; set; } +} +```` + +`BasicAggregateRoot` is the simplest base class to create root entities, and `Guid` is the primary key (`Id`) of the entity here. + +## Database Integration + +{{if DB=="EF"}} + +Next step is to setup the [Entity Framework Core](../../../Entity-Framework-Core.md) configuration. + +### Mapping Configuration + +Open the `TodoAppDbContext` class (it's under the **Data** folder) and add a new `DbSet` property to this class: + +````csharp +public DbSet TodoItems { get; set; } +```` + +Then navigate to the `OnModelCreating` method in the same class and add the mapping code for the `TodoItem ` entity: + +````csharp +protected override void OnModelCreating(ModelBuilder builder) +{ + base.OnModelCreating(builder); + + /* Include modules to your migration db context */ + + builder.ConfigurePermissionManagement(); + ... + + /* Configure your own tables/entities inside here */ + builder.Entity(b => + { + b.ToTable("TodoItems"); + }); +} +```` + +We've mapped the `TodoItem` entity to the `TodoItems` table in the database. The next step is creating a migration and apply the changes to the database. + +### Code First Migrations + +The startup solution is configured to use Entity Framework Core [Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database. + +Open a command-line terminal in the directory of your project and type the following command: + +````bash +dotnet ef migrations add Added_TodoItem +```` + +This will add a new migration class to the project: + +![todo-efcore-migration](../todo-efcore-migration-single-layer.png) TODO: add this screenshot??? + +You can apply changes to the database using the following command, in the same command-line terminal: + +````bash +dotnet ef database update +```` + +{{else if DB=="Mongo"}} + +Next step is to setup the [MongoDB](../../../MongoDB.md) configuration. Open the `TodoAppMongoDbContext` class (it's under the **Data** folder) in your project and make the following changes: + +1. Add a new property to the class: + +````csharp +public IMongoCollection TodoItems => Collection(); +```` + +2. Add the following code inside the `CreateModel` method: + +````csharp +modelBuilder.Entity(b => +{ + b.CollectionName = "TodoItems"; +}); +```` + +{{end}} + +After the database integrations, now we can start to create application service methods and implement our use-cases. + +## Creating the Application Service Interface + +An [Application Service](../../Application-Services.md) is used to perform the use cases of the application. We need to perform the following use cases in this application: + +* Get the list of the todo items +* Create a new todo item +* Delete an existing todo item + +Let's start with defining an interface for the application service. Create a new `ITodoAppService` interface under the **Services** folder, as shown below: + +```csharp +using TodoApp.Services.Dtos; +using Volo.Abp.Application.Services; + +namespace TodoApp.Services; + +public interface ITodoAppService : IApplicationService +{ + Task> GetListAsync(); + Task CreateAsync(string text); + Task DeleteAsync(Guid id); +} +``` + +## Creating the Data Transfer Object (DTO) + +`GetListAsync` and `CreateAsync` methods return `TodoItemDto`. `ApplicationService` typically gets and returns DTOs ([Data Transfer Objects](../../../Data-Transfer-Objects.md)) instead of entities but we haven't created it yet. So, create a new `TodoItemDto` class under the **Dtos** folder (it's under the **Services** folder): + +```csharp +namespace TodoApp.Services.Dtos; + +public class TodoItemDto +{ + public Guid Id { get; set; } + public string Text { get; set; } +} +``` + +This is a very simple DTO class that have the same properties with our `TodoItem` entity. We are ready to implement the `ITodoAppService`. + +## Application Service Implementation + +Create a `TodoAppService` class under the **Services** folder of your project, as shown below: + +```csharp +using TodoApp.Entities; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; + +namespace TodoApp.Services; + +public class TodoAppService : ApplicationService, ITodoAppService +{ + private readonly IRepository _todoItemRepository; + + public TodoAppService(IRepository todoItemRepository) + { + _todoItemRepository = todoItemRepository; + } + + // TODO: Implement the methods here... +} +``` + +This class inherits from the `ApplicationService` class of the ABP Framework and implements the `ITodoAppService` that created in the [Creating the Application Service Interface](#creating-the-application-service-interface) section. ABP provides default generic [repositories](../../../Repositories.md) for the entities. We can use them to perform the fundamental database operations. This class [injects](../../../Dependency-Injection.md) `IRepository`, which is the default repository for the `TodoItem` entity. We will use it to implement the use cases described before. + +### Getting Todo Items + +Let's start by implementing the `GetListAsync` method: + +````csharp +public async Task> GetListAsync() +{ + var items = await _todoItemRepository.GetListAsync(); + return items + .Select(item => new TodoItemDto + { + Id = item.Id, + Text = item.Text + }).ToList(); +} +```` + +We are simply getting the complete `TodoItem` list from the database, mapping them to `TodoItemDto` objects and returning as the result. + +#### Creating a New Todo Item + +Next method is `CreateAsync` and we can implement it as shown below: + +````csharp +public async Task CreateAsync(string text) +{ + var todoItem = await _todoItemRepository.InsertAsync( + new TodoItem {Text = text} + ); + + return new TodoItemDto + { + Id = todoItem.Id, + Text = todoItem.Text + }; +} +```` + +The repository's `InsertAsync` method inserts the given `TodoItem` to the database and returns the same `TodoItem` object. It also sets the `Id`, so we can use it on the returning object. We are simply returning a `TodoItemDto` by creating from the new `TodoItem` entity. + +#### Deleting a Todo Item + +Finally, we can implement the `DeleteAsync` as the following code block: + +````csharp +public async Task DeleteAsync(Guid id) +{ + await _todoItemRepository.DeleteAsync(id); +} +```` + +The application service is ready to be used from the UI layer. + +## User Interface Layer + +It is time to show the todo items on the UI! Before starting to write the code, it would be good to remember what we are trying to build. Here's a sample screenshot from the final UI: + +![todo-list](../todo-list.png) + +{{if UI=="MVC"}} + +{{else if UI=="BlazorServer"}} + +{{else if UI=="NG"}} + +{{end}} + +## Conclusion + +In this tutorial, we've built a very simple application to warm up with the ABP Framework. + +## Source Code + +You can find source code of the completed application [here](https://github.com/abpframework/abp-samples/tree/master/TodoApp). + +## See Also + +* [Web Application Development Tutorial](../Part-1.md) to see a real-life web application development in a layered architecture. \ No newline at end of file From d7efec5df502926bfc534647a239cacd26618c21 Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Tue, 17 May 2022 15:53:15 +0300 Subject: [PATCH 2/7] Update Quick Start documentation for `app-nolayers` --- docs/en/Tutorials/Todo/Single-Layer/Index.md | 205 ++++++++++++++++-- .../todo-efcore-migration-single-layer.png | Bin 0 -> 8866 bytes 2 files changed, 188 insertions(+), 17 deletions(-) create mode 100644 docs/en/Tutorials/Todo/Single-Layer/todo-efcore-migration-single-layer.png diff --git a/docs/en/Tutorials/Todo/Single-Layer/Index.md b/docs/en/Tutorials/Todo/Single-Layer/Index.md index fe70013e19..e902f3108c 100644 --- a/docs/en/Tutorials/Todo/Single-Layer/Index.md +++ b/docs/en/Tutorials/Todo/Single-Layer/Index.md @@ -12,7 +12,7 @@ This is a single-part quick-start tutorial to build a simple todo application wi ![todo-list](../todo-list.png) -You can find the source code of the completed application [here](TODO: sample's url???). +You can find the source code of the completed application [here](https://github.com/abpframework/abp-samples/tree/master/TodoApp). ## Pre-Requirements @@ -46,11 +46,11 @@ abp new TodoApp -t app-nolayers{{if UI=="BlazorServer"}} -u blazor-server{{else {{if UI=="NG"}} -This will create a new solution with a single-project, named *TodoApp* with `angular` and `aspnet-core` folders. Once the solution is ready, open the solution in your favorite IDE. +This will create a new solution with a single project, named *TodoApp* with `angular` and `aspnet-core` folders. Once the solution is ready, open the solution in your favorite IDE. {{else}} -This will create a new solution with a single-project, named *TodoApp*. Once the solution is ready, open it in your favorite IDE. +This will create a new solution with a single project, named *TodoApp*. Once the solution is ready, open it in your favorite IDE. {{end}} @@ -68,13 +68,13 @@ This command will create the database and seed the initial data for you. Then yo {{if UI=="MVC" || UI=="BlazorServer"}} -It is good to run the application before starting the development. Running the application is pretty straigth-forward, you can run the application with any IDE that supports .NET or by running the `dotnet run` CLI command in the directory of your project to see the initial UI: +It is good to run the application before starting the development. Running the application is pretty straight-forward, you can run the application with any IDE that supports .NET or by running the `dotnet run` CLI command in the directory of your project: {{else if UI=="NG"}} It is good to run the application before starting the development. The solution has two main applications: -* `TodoApp` (in the .NET solution) host the server-side HTTP API, so Angular application can consume it. (server-side application) +* `TodoApp` (in the .NET solution) hosts the server-side HTTP API, so the Angular application can consume it. (server-side application) * `angular` folder contains the Angular application. (client-side application) Firstly, run the `TodoApp` project in your favorite IDE (or run the `dotnet run` CLI command on your project directory) to see the server-side HTTP API on the [Swagger UI](https://swagger.io/tools/swagger-ui/): @@ -101,9 +101,9 @@ This command takes time, but eventually runs and opens the application in your d ![todo-ui-initial](../todo-ui-initial.png) -You can click on the *Login* button, use `admin` as the username and `1q2w3E*` as the password to login to the application. +You can click on the *Login* button and use `admin` as the username and `1q2w3E*` as the password to login to the application. -All ready. We can start coding! +All right. We can start coding! ## Defining Entities @@ -156,7 +156,7 @@ protected override void OnModelCreating(ModelBuilder builder) } ```` -We've mapped the `TodoItem` entity to the `TodoItems` table in the database. The next step is creating a migration and apply the changes to the database. +We've mapped the `TodoItem` entity to the `TodoItems` table in the database. The next step is to create a migration and apply the changes to the database. ### Code First Migrations @@ -168,11 +168,11 @@ Open a command-line terminal in the directory of your project and type the follo dotnet ef migrations add Added_TodoItem ```` -This will add a new migration class to the project: +This will add a new migration class to the project. You should see the migration in the **Migrations** folder. -![todo-efcore-migration](../todo-efcore-migration-single-layer.png) TODO: add this screenshot??? +![todo-efcore-migration](todo-efcore-migration-single-layer.png) -You can apply changes to the database using the following command, in the same command-line terminal: +Then, you can apply changes to the database using the following command, in the same command-line terminal: ````bash dotnet ef database update @@ -180,7 +180,7 @@ dotnet ef database update {{else if DB=="Mongo"}} -Next step is to setup the [MongoDB](../../../MongoDB.md) configuration. Open the `TodoAppMongoDbContext` class (it's under the **Data** folder) in your project and make the following changes: +The next step is to setup the [MongoDB](../../../MongoDB.md) configuration. Open the `TodoAppMongoDbContext` class (it's under the **Data** folder) in your project and make the following changes: 1. Add a new property to the class: @@ -239,7 +239,7 @@ public class TodoItemDto } ``` -This is a very simple DTO class that have the same properties with our `TodoItem` entity. We are ready to implement the `ITodoAppService`. +This is a very simple DTO class that has the same properties as the `TodoItem` entity. We are ready to implement the `ITodoAppService`. ## Application Service Implementation @@ -284,11 +284,11 @@ public async Task> GetListAsync() } ```` -We are simply getting the complete `TodoItem` list from the database, mapping them to `TodoItemDto` objects and returning as the result. +We are simply getting the `TodoItem` list from the database, mapping them to `TodoItemDto` objects and returning as the result. #### Creating a New Todo Item -Next method is `CreateAsync` and we can implement it as shown below: +The next method is `CreateAsync` and we can implement it as shown below: ````csharp public async Task CreateAsync(string text) @@ -328,8 +328,179 @@ It is time to show the todo items on the UI! Before starting to write the code, {{if UI=="MVC"}} +### Index.cshtml.cs + +Open the `Index.cshtml.cs` file in the `Pages` folder and replace the content with the following code block: + +```csharp +using TodoApp.Services; +using TodoApp.Services.Dtos; +using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; + +namespace TodoApp.Pages; + +public class IndexModel : AbpPageModel +{ + public List TodoItems { get; set; } + + private readonly ITodoAppService _todoAppService; + + public IndexModel(ITodoAppService todoAppService) + { + _todoAppService = todoAppService; + } + + public async Task OnGetAsync() + { + TodoItems = await _todoAppService.GetListAsync(); + } +} +``` + +This class uses the `ITodoAppService` to get the list of todo items and assign the `TodoItems` property. We will use it to render the todo items on the razor page. + +### Index.cshtml + +Open the `Index.cshtml` file in the `Pages` folder and replace it with the following content: + +```xml +@page +@model TodoApp.Pages.IndexModel + +@section styles { + +} +@section scripts { + +} + +
+ + + + TODO LIST + + + + +
+
+
+ +
+
+
+ +
+
+ +
    + @foreach (var todoItem in Model.TodoItems) + { +
  • + @todoItem.Text +
  • + } +
+
+
+
+``` + +We are using ABP's [card tag helper](../../UI/AspNetCore/Tag-Helpers/Cards.md) to create a simple card view. You could directly use the standard bootstrap HTML structure, however the ABP [tag helpers](../../UI/AspNetCore/Tag-Helpers/Index.md) make it much easier and type safe. + +This page imports a CSS and a JavaScript file, so we should also create them. + +### Index.js + +Create an `Index.js` file in the `Pages` folder and add the following content: + +````js +$(function () { + + // DELETING ITEMS ///////////////////////////////////////// + $('#TodoList').on('click', 'li i', function(){ + var $li = $(this).parent(); + var id = $li.attr('data-id'); + + todoApp.services.todo.delete(id).then(function(){ + $li.remove(); + abp.notify.info('Deleted the todo item.'); + }); + }); + + // CREATING NEW ITEMS ///////////////////////////////////// + $('#NewItemForm').submit(function(e){ + e.preventDefault(); + + var todoText = $('#NewItemText').val(); + todoApp.services.todo.create(todoText).then(function(result){ + $('
  • ') + .html(' ' + result.text) + .appendTo($('#TodoList')); + $('#NewItemText').val(''); + }); + }); +}); +```` + +In the first part, we are subscribing to the click events of the trash icons near the todo items, deleting the related item on the server and showing a notification on the UI. Also, we are removing the deleted item from the DOM, so we don't need to refresh the page. + +In the second part, we are creating a new todo item on the server. If it succeeds, we are then manipulating the DOM to insert a new `
  • ` element to the todo list. This way we don't need to refresh the whole page after creating a new todo item. + +The interesting part here is how we communicate with the server. See the [*Dynamic JavaScript Proxies & Auto API Controllers*](#dynamic-javascript-proxies--auto-api-controllers) section to understand how it works. But now, let's continue and complete the application. + +### Index.css + +As the final touch, create the `Index.css` file in the `Pages` folder and add the following content: + +````css +#TodoList{ + list-style: none; + margin: 0; + padding: 0; +} + +#TodoList li { + padding: 5px; + margin: 5px 0px; + border: 1px solid #cccccc; + background-color: #f5f5f5; +} + +#TodoList li i +{ + opacity: 0.5; +} + +#TodoList li i:hover +{ + opacity: 1; + color: #ff0000; + cursor: pointer; +} +```` + +This is a simple styling for the todo page. We believe that you can do much better :) + +Now, you can run the application again and see the result. + +### Dynamic JavaScript Proxies & Auto API Controllers + +In the `Index.js` file, we've used the `todoApp.services.todo.delete(...)` and `todoApp.services.todo.create(...)` functions to communicate with the server. These functions are dynamically created by the ABP Framework, thanks to the [Dynamic JavaScript Client Proxy](../../../UI/AspNetCore/Dynamic-JavaScript-Proxies.md) system. They perform HTTP API calls to the server and return a promise, so you can register a callback to the `then` function as we've done above. + +> **services** keyword comes from the namespace (`namespace TodoApp.Services;`). + +However, you may notice that we haven't created any API Controllers, so how does the server handle these requests? This question brings us to the [Auto API Controller](../../../API/Auto-API-Controllers.md) feature of the ABP Framework. It automatically converts the application services to **API Controllers** by convention. + +If you open the [Swagger UI](https://swagger.io/tools/swagger-ui/) by entering the `/swagger` URL in your application, you can see the Todo API: + +![todo-api](../todo-api.png) + + {{else if UI=="BlazorServer"}} + {{else if UI=="NG"}} {{end}} @@ -340,8 +511,8 @@ In this tutorial, we've built a very simple application to warm up with the ABP ## Source Code -You can find source code of the completed application [here](https://github.com/abpframework/abp-samples/tree/master/TodoApp). +You can find the source code of the completed application [here](https://github.com/abpframework/abp-samples/tree/master/TodoApp). ## See Also -* [Web Application Development Tutorial](../Part-1.md) to see a real-life web application development in a layered architecture. \ No newline at end of file +* Check the [Web Application Development Tutorial](../Part-1.md) to see a real-life web application development in a layered architecture using the [Application Startup Template](../../../Startup-Templates/Application.md). \ No newline at end of file diff --git a/docs/en/Tutorials/Todo/Single-Layer/todo-efcore-migration-single-layer.png b/docs/en/Tutorials/Todo/Single-Layer/todo-efcore-migration-single-layer.png new file mode 100644 index 0000000000000000000000000000000000000000..686d8a5f87be890ca789998d6cbafae931e872da GIT binary patch literal 8866 zcmb7~Wl$VZxT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ozO?bx|N1OvB!FzLI9q}|F8F?G@a@$UlO!b6@ z_zZ$xKmaFWsf_3dWQP3u=OG5fsFJv#dJ`56vNYMVS~YcJ;vZXZ4fo-AM(@vkzGcFq zGr2xrIG>|{5A-O$1tP1&j@~#4f{VWI#GlZ18-w` z#4|6xgUvbISg5^<{_XQriLsg@((_V$SK^NUCDlP0F~BxtWxX0N0Z zIO9T~^Kvi#&BqNc+@Z>mWvnt?C`Fu%TnD}6s{2s;iqW%*V3(YUCGM7X`2{H@^#Cg* z_YcW}Cu{|Zu73bETx@DO0y~%;#B}vKio7?TX=-kTfrILQ$brP?5`zqH^>XsX9q-GL zZZI2A;jMSc|K@KjxFOtmLAXk((4>*@%lEm4AHaF;ujQ@M4PDoF{IxT9LgZZc^+V<3 zt1B6uTGv=J$%70=X-OsCBFAMQZY}GREiW0(5O43h$UGs<9ojql)1Nw3J=H?nrz*-K ziz8zfb+Cls@RHQZDx5omZl7cp{X2RcFsiZu($K?P+&mBMx7xneu3uF@Cxx4}LC?@U zb_o2xpse}PDf8XSQ~y#!)rJ3pH(39=jjE^l4GBuzT2_|%{X+oCoy_#H_TNTP@whf^ zjO%6DSqqCG-_NDBsA|ZDM;;SdIpGq(oB}~zhq*>U+2Zp%1|mb7W8`Ck5WU-t5GuMM zX>)12*JF2{Irr#ho+`nsz!5}%#Wme*%vX1rn)p72vXIdtFI0>d2@qmhmNP;ZniJCk zl0{Gh-glZAKIyfdN>2CUczKE1h_$9G-q{TnYh~<9XjN!ZZk7 zX+4>A$cmXteoAhY9j_kZc1m7RJ{$M(??Oz3nkM9w>fM-qVYU3H+jubln-6;br&^ Date: Wed, 18 May 2022 12:25:07 +0300 Subject: [PATCH 3/7] Update Index.md --- docs/en/Tutorials/Todo/Single-Layer/Index.md | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/en/Tutorials/Todo/Single-Layer/Index.md b/docs/en/Tutorials/Todo/Single-Layer/Index.md index e902f3108c..dff251b881 100644 --- a/docs/en/Tutorials/Todo/Single-Layer/Index.md +++ b/docs/en/Tutorials/Todo/Single-Layer/Index.md @@ -77,7 +77,7 @@ It is good to run the application before starting the development. The solution * `TodoApp` (in the .NET solution) hosts the server-side HTTP API, so the Angular application can consume it. (server-side application) * `angular` folder contains the Angular application. (client-side application) -Firstly, run the `TodoApp` project in your favorite IDE (or run the `dotnet run` CLI command on your project directory) to see the server-side HTTP API on the [Swagger UI](https://swagger.io/tools/swagger-ui/): +Firstly, run the `TodoApp` project in your favorite IDE (or run the `dotnet run` CLI command on your project directory) to see the server-side HTTP API on [Swagger UI](https://swagger.io/tools/swagger-ui/): ![todo-swagger-ui-initial](../todo-swagger-ui-initial.png) @@ -89,7 +89,7 @@ First, run the following command (or `yarn install`) to restore the NPM packages npm install ```` -It will take some time to install all packages. Then you can run the application using the following (or `yarn start`) command: +It will take some time to install all the packages. Then you can run the application using the following (or `yarn start`) command: ````bash npm start @@ -130,7 +130,7 @@ Next step is to setup the [Entity Framework Core](../../../Entity-Framework-Core ### Mapping Configuration -Open the `TodoAppDbContext` class (it's under the **Data** folder) and add a new `DbSet` property to this class: +Open the `TodoAppDbContext` class (under the **Data** folder) and add a new `DbSet` property to this class: ````csharp public DbSet TodoItems { get; set; } @@ -158,7 +158,7 @@ protected override void OnModelCreating(ModelBuilder builder) We've mapped the `TodoItem` entity to the `TodoItems` table in the database. The next step is to create a migration and apply the changes to the database. -### Code First Migrations +### Code the First Migrations The startup solution is configured to use Entity Framework Core [Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database. @@ -265,9 +265,9 @@ public class TodoAppService : ApplicationService, ITodoAppService } ``` -This class inherits from the `ApplicationService` class of the ABP Framework and implements the `ITodoAppService` that created in the [Creating the Application Service Interface](#creating-the-application-service-interface) section. ABP provides default generic [repositories](../../../Repositories.md) for the entities. We can use them to perform the fundamental database operations. This class [injects](../../../Dependency-Injection.md) `IRepository`, which is the default repository for the `TodoItem` entity. We will use it to implement the use cases described before. +This class inherits from the `ApplicationService` class of the ABP Framework and implements the `ITodoAppService` that was created in the [Creating the Application Service Interface](#creating-the-application-service-interface) section. ABP provides default generic [repositories](../../../Repositories.md) for the entities. We can use them to perform the fundamental database operations. This class [injects](../../../Dependency-Injection.md) `IRepository`, which is the default repository for the `TodoItem` entity. We will use it to implement the use cases described before. -### Getting Todo Items +### Getting the Todo Items Let's start by implementing the `GetListAsync` method: @@ -284,7 +284,7 @@ public async Task> GetListAsync() } ```` -We are simply getting the `TodoItem` list from the database, mapping them to `TodoItemDto` objects and returning as the result. +We are simply getting the `TodoItem` list from the database, mapping them to the `TodoItemDto` objects and returning as the result. #### Creating a New Todo Item @@ -357,7 +357,7 @@ public class IndexModel : AbpPageModel } ``` -This class uses the `ITodoAppService` to get the list of todo items and assign the `TodoItems` property. We will use it to render the todo items on the razor page. +This class uses `ITodoAppService` to get the list of todo items and assign the `TodoItems` property. We will use it to render the todo items on the razor page. ### Index.cshtml @@ -444,15 +444,15 @@ $(function () { }); ```` -In the first part, we are subscribing to the click events of the trash icons near the todo items, deleting the related item on the server and showing a notification on the UI. Also, we are removing the deleted item from the DOM, so we don't need to refresh the page. +In the first part, we subscribed to the click events of the trash icons near the todo items, deleted the related item on the server and showed a notification on the UI. Also, we removed the deleted item from the DOM, so we wouldn't need to refresh the page. -In the second part, we are creating a new todo item on the server. If it succeeds, we are then manipulating the DOM to insert a new `
  • ` element to the todo list. This way we don't need to refresh the whole page after creating a new todo item. +In the second part, we created a new todo item on the server. If it succeeded, we would then manipulate the DOM to insert a new `
  • ` element to the todo list. This way, we wouldn't need to refresh the whole page after creating a new todo item. The interesting part here is how we communicate with the server. See the [*Dynamic JavaScript Proxies & Auto API Controllers*](#dynamic-javascript-proxies--auto-api-controllers) section to understand how it works. But now, let's continue and complete the application. ### Index.css -As the final touch, create the `Index.css` file in the `Pages` folder and add the following content: +As for the final touch, create the `Index.css` file in the `Pages` folder and add the following content: ````css #TodoList{ @@ -493,7 +493,7 @@ In the `Index.js` file, we've used the `todoApp.services.todo.delete(...)` and ` However, you may notice that we haven't created any API Controllers, so how does the server handle these requests? This question brings us to the [Auto API Controller](../../../API/Auto-API-Controllers.md) feature of the ABP Framework. It automatically converts the application services to **API Controllers** by convention. -If you open the [Swagger UI](https://swagger.io/tools/swagger-ui/) by entering the `/swagger` URL in your application, you can see the Todo API: +If you open [Swagger UI](https://swagger.io/tools/swagger-ui/) by entering the `/swagger` URL in your application, you can see the Todo API: ![todo-api](../todo-api.png) @@ -515,4 +515,4 @@ You can find the source code of the completed application [here](https://github. ## See Also -* Check the [Web Application Development Tutorial](../Part-1.md) to see a real-life web application development in a layered architecture using the [Application Startup Template](../../../Startup-Templates/Application.md). \ No newline at end of file +* Check the [Web Application Development Tutorial](../Part-1.md) to see a real-life web application development in a layered architecture using the [Application Startup Template](../../../Startup-Templates/Application.md). From d9e01eb6077baafe36ab5693345ec1592971b46e Mon Sep 17 00:00:00 2001 From: Engincan VESKE <43685404+EngincanV@users.noreply.github.com> Date: Wed, 18 May 2022 12:27:48 +0300 Subject: [PATCH 4/7] Update Index.md --- docs/en/Tutorials/Todo/Single-Layer/Index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/Tutorials/Todo/Single-Layer/Index.md b/docs/en/Tutorials/Todo/Single-Layer/Index.md index dff251b881..2ae6b49df7 100644 --- a/docs/en/Tutorials/Todo/Single-Layer/Index.md +++ b/docs/en/Tutorials/Todo/Single-Layer/Index.md @@ -158,7 +158,7 @@ protected override void OnModelCreating(ModelBuilder builder) We've mapped the `TodoItem` entity to the `TodoItems` table in the database. The next step is to create a migration and apply the changes to the database. -### Code the First Migrations +### Code First Migrations The startup solution is configured to use Entity Framework Core [Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database. From 554884e822db655cb4fb87522ed363c143b4f86a Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 20 May 2022 15:29:26 +0300 Subject: [PATCH 5/7] Update Index.md --- docs/en/Tutorials/Todo/Single-Layer/Index.md | 185 ++++++++++++++----- 1 file changed, 142 insertions(+), 43 deletions(-) diff --git a/docs/en/Tutorials/Todo/Single-Layer/Index.md b/docs/en/Tutorials/Todo/Single-Layer/Index.md index 2ae6b49df7..a53ff0a15a 100644 --- a/docs/en/Tutorials/Todo/Single-Layer/Index.md +++ b/docs/en/Tutorials/Todo/Single-Layer/Index.md @@ -12,7 +12,7 @@ This is a single-part quick-start tutorial to build a simple todo application wi ![todo-list](../todo-list.png) -You can find the source code of the completed application [here](https://github.com/abpframework/abp-samples/tree/master/TodoApp). +You can find the source code of the completed application [here](https://github.com/abpframework/abp-samples/tree/master/TodoApp-SingleLayer). ## Pre-Requirements @@ -81,15 +81,9 @@ Firstly, run the `TodoApp` project in your favorite IDE (or run the `dotnet run` ![todo-swagger-ui-initial](../todo-swagger-ui-initial.png) -You can explore and test your HTTP API with this UI. If it works, we can run the Angular client application. +You can explore and test your HTTP API with this UI. If it works, then we can run the Angular client application. -First, run the following command (or `yarn install`) to restore the NPM packages: - -````bash -npm install -```` - -It will take some time to install all the packages. Then you can run the application using the following (or `yarn start`) command: +You can run the application using the following (or `yarn start`) command: ````bash npm start @@ -107,7 +101,7 @@ All right. We can start coding! ## Defining Entities -This application will have a single [entity](../../../Entities.md) and we can start by creating it. So, create a new `TodoItem` class under the **Entities** folder of the project. +This application will have a single [entity](../../../Entities.md) and we can start by creating it. So, create a new `TodoItem` class under the **Entities** folder of the project: ````csharp using Volo.Abp.Domain.Entities; @@ -136,7 +130,7 @@ Open the `TodoAppDbContext` class (under the **Data** folder) and add a new `DbS public DbSet TodoItems { get; set; } ```` -Then navigate to the `OnModelCreating` method in the same class and add the mapping code for the `TodoItem ` entity: +Then navigate to the `OnModelCreating` method in the same class and add the following mapping code for the `TodoItem ` entity: ````csharp protected override void OnModelCreating(ModelBuilder builder) @@ -168,7 +162,7 @@ Open a command-line terminal in the directory of your project and type the follo dotnet ef migrations add Added_TodoItem ```` -This will add a new migration class to the project. You should see the migration in the **Migrations** folder. +This will add a new migration class to the project. You should see the new migration in the **Migrations** folder. ![todo-efcore-migration](todo-efcore-migration-single-layer.png) @@ -180,7 +174,7 @@ dotnet ef database update {{else if DB=="Mongo"}} -The next step is to setup the [MongoDB](../../../MongoDB.md) configuration. Open the `TodoAppMongoDbContext` class (it's under the **Data** folder) in your project and make the following changes: +The next step is to setup the [MongoDB](../../../MongoDB.md) configuration. Open the `TodoAppDbContext` class (under the **Data** folder) in your project and make the following changes: 1. Add a new property to the class: @@ -201,7 +195,7 @@ modelBuilder.Entity(b => After the database integrations, now we can start to create application service methods and implement our use-cases. -## Creating the Application Service Interface +## Creating the Application Service An [Application Service](../../Application-Services.md) is used to perform the use cases of the application. We need to perform the following use cases in this application: @@ -209,25 +203,11 @@ An [Application Service](../../Application-Services.md) is used to perform the u * Create a new todo item * Delete an existing todo item -Let's start with defining an interface for the application service. Create a new `ITodoAppService` interface under the **Services** folder, as shown below: - -```csharp -using TodoApp.Services.Dtos; -using Volo.Abp.Application.Services; - -namespace TodoApp.Services; - -public interface ITodoAppService : IApplicationService -{ - Task> GetListAsync(); - Task CreateAsync(string text); - Task DeleteAsync(Guid id); -} -``` +Before starting to implement these use cases, first we need to create DTOs. -## Creating the Data Transfer Object (DTO) +### Creating the Data Transfer Object (DTO) -`GetListAsync` and `CreateAsync` methods return `TodoItemDto`. `ApplicationService` typically gets and returns DTOs ([Data Transfer Objects](../../../Data-Transfer-Objects.md)) instead of entities but we haven't created it yet. So, create a new `TodoItemDto` class under the **Dtos** folder (it's under the **Services** folder): +`ApplicationService` typically gets and returns DTOs ([Data Transfer Objects](../../../Data-Transfer-Objects.md)) instead of entities. So, create a new `TodoItemDto` class under the **Dtos** folder (under the **Services** folder): ```csharp namespace TodoApp.Services.Dtos; @@ -239,9 +219,9 @@ public class TodoItemDto } ``` -This is a very simple DTO class that has the same properties as the `TodoItem` entity. We are ready to implement the `ITodoAppService`. +* This is a very simple DTO class that has the same properties as the `TodoItem` entity. Now, we are ready to implement our use-cases. -## Application Service Implementation +### Application Service Implementation Create a `TodoAppService` class under the **Services** folder of your project, as shown below: @@ -252,7 +232,7 @@ using Volo.Abp.Domain.Repositories; namespace TodoApp.Services; -public class TodoAppService : ApplicationService, ITodoAppService +public class TodoAppService : ApplicationService { private readonly IRepository _todoItemRepository; @@ -265,9 +245,9 @@ public class TodoAppService : ApplicationService, ITodoAppService } ``` -This class inherits from the `ApplicationService` class of the ABP Framework and implements the `ITodoAppService` that was created in the [Creating the Application Service Interface](#creating-the-application-service-interface) section. ABP provides default generic [repositories](../../../Repositories.md) for the entities. We can use them to perform the fundamental database operations. This class [injects](../../../Dependency-Injection.md) `IRepository`, which is the default repository for the `TodoItem` entity. We will use it to implement the use cases described before. +This class inherits from the `ApplicationService` class of the ABP Framework and implements our use-cases. ABP provides default generic [repositories](../../../Repositories.md) for the entities. We can use them to perform the fundamental database operations. This class [injects](../../../Dependency-Injection.md) `IRepository`, which is the default repository for the `TodoItem` entity. We will use it to implement the use cases (`GetListAsync`, `CreateAsync` and `DeleteAsync`) described before. -### Getting the Todo Items +#### Getting the Todo Items Let's start by implementing the `GetListAsync` method: @@ -318,9 +298,9 @@ public async Task DeleteAsync(Guid id) } ```` -The application service is ready to be used from the UI layer. +The application service is ready to be used from the UI layer. So, let's implement it. -## User Interface Layer +## User Interface It is time to show the todo items on the UI! Before starting to write the code, it would be good to remember what we are trying to build. Here's a sample screenshot from the final UI: @@ -343,9 +323,9 @@ public class IndexModel : AbpPageModel { public List TodoItems { get; set; } - private readonly ITodoAppService _todoAppService; + private readonly TodoAppService _todoAppService; - public IndexModel(ITodoAppService todoAppService) + public IndexModel(TodoAppService todoAppService) { _todoAppService = todoAppService; } @@ -357,7 +337,7 @@ public class IndexModel : AbpPageModel } ``` -This class uses `ITodoAppService` to get the list of todo items and assign the `TodoItems` property. We will use it to render the todo items on the razor page. +This class uses `TodoAppService` to get the list of todo items and assign the `TodoItems` property. We will use it to render the todo items on the razor page. ### Index.cshtml @@ -497,9 +477,128 @@ If you open [Swagger UI](https://swagger.io/tools/swagger-ui/) by entering the ` ![todo-api](../todo-api.png) - {{else if UI=="BlazorServer"}} +### Index.razor.cs + +Open the `Index.razor.cs` file in the `Pages` folder and replace the content with the following code block: + +```csharp +using Microsoft.AspNetCore.Components; +using TodoApp.Services; +using TodoApp.Services.Dtos; + +namespace TodoApp.Pages; + +public partial class Index +{ + [Inject] + private TodoAppService TodoAppService { get; set; } + + private List TodoItems { get; set; } = new List(); + private string NewTodoText { get; set; } + + protected override async Task OnInitializedAsync() + { + TodoItems = await TodoAppService.GetListAsync(); + } + + private async Task Create() + { + var result = await TodoAppService.CreateAsync(NewTodoText); + TodoItems.Add(result); + NewTodoText = null; + } + + private async Task Delete(TodoItemDto todoItem) + { + await TodoAppService.DeleteAsync(todoItem.Id); + await Notify.Info("Deleted the todo item."); + TodoItems.Remove(todoItem); + } +} +``` + +This class uses the `TodoAppService` to get the list of todo items. It manipulates the `TodoItems` list after create and delete operations. This way, we don't need to refresh the whole todo list from the server. + +### Index.razor + +Open the `Index.razor` file in the `Pages` folder and replace the content with the following code block: + +```xml +@page "/" +@inherits TodoAppComponentBase + +
    + + + + TODO LIST + + + + +
    +
    +
    + +
    +
    +
    + +
    +
    + +
      + @foreach (var todoItem in TodoItems) + { +
    • + + @todoItem.Text +
    • + } +
    +
    +
    +
    +``` + +### Index.razor.css + +As the final touch, open the `Index.razor.css` file in the `Pages` folder and replace it with the following content: + +````css +#TodoList{ + list-style: none; + margin: 0; + padding: 0; +} + +#TodoList li { + padding: 5px; + margin: 5px 0px; + border: 1px solid #cccccc; + background-color: #f5f5f5; +} + +#TodoList li i +{ + opacity: 0.5; +} + +#TodoList li i:hover +{ + opacity: 1; + color: #ff0000; + cursor: pointer; +} +```` + +This is a simple styling for the todo page. We believe that you can do much better :) + +Now, you can run the application again to see the result. + {{else if UI=="NG"}} @@ -511,7 +610,7 @@ In this tutorial, we've built a very simple application to warm up with the ABP ## Source Code -You can find the source code of the completed application [here](https://github.com/abpframework/abp-samples/tree/master/TodoApp). +You can find the source code of the completed application [here](https://github.com/abpframework/abp-samples/tree/master/TodoApp-SingleLayer). ## See Also From 946a54b4c57dc948d8cd7c3e2fcd93487b0ba75c Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Sat, 21 May 2022 11:43:11 +0300 Subject: [PATCH 6/7] Update Index.md --- docs/en/Tutorials/Todo/Single-Layer/Index.md | 145 ++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/docs/en/Tutorials/Todo/Single-Layer/Index.md b/docs/en/Tutorials/Todo/Single-Layer/Index.md index a53ff0a15a..244b30acb9 100644 --- a/docs/en/Tutorials/Todo/Single-Layer/Index.md +++ b/docs/en/Tutorials/Todo/Single-Layer/Index.md @@ -599,9 +599,152 @@ This is a simple styling for the todo page. We believe that you can do much bett Now, you can run the application again to see the result. - {{else if UI=="NG"}} +### Service Proxy Generation + +ABP provides a handy feature to automatically create client-side services to easily consume HTTP APIs provided by the server. + +You first need to run the `TodoApp` project since the proxy generator reads API definitions from the server application. + +Once you run the `TodoApp` project (**Swagger API Definition** will be shown), open a command-line terminal in the directory of `angular` folder and run the following command: + +```bash +abp generate-proxy -t ng +``` + +If everything goes well, it should generate an output as shown below: + +```bash +CREATE src/app/proxy/generate-proxy.json (182755 bytes) +CREATE src/app/proxy/README.md (1000 bytes) +CREATE src/app/proxy/services/todo.service.ts (833 bytes) +CREATE src/app/proxy/services/dtos/models.ts (71 bytes) +CREATE src/app/proxy/services/dtos/index.ts (26 bytes) +CREATE src/app/proxy/services/index.ts (81 bytes) +CREATE src/app/proxy/index.ts (61 bytes) +``` + +Then, we can use the `TodoService` to use the server-side HTTP APIs, as we'll do in the next section. + +### home.component.ts + +Open the `/angular/src/app/home/home.component.ts` file and replace its content with the following code block: + +```ts +import { ToasterService } from "@abp/ng.theme.shared"; +import { Component, OnInit } from '@angular/core'; +import { TodoItemDto } from "@proxy/services/dtos"; +import { TodoService } from "@proxy/services"; + +@Component({ + selector: 'app-home', + templateUrl: './home.component.html', + styleUrls: ['./home.component.scss'], +}) + +export class HomeComponent implements OnInit { + + todoItems: TodoItemDto[]; + newTodoText: string; + + constructor( + private todoService: TodoService, + private toasterService: ToasterService) + { } + + ngOnInit(): void { + this.todoService.getList().subscribe(response => { + this.todoItems = response; + }); + } + + create(): void{ + this.todoService.create(this.newTodoText).subscribe((result) => { + this.todoItems = this.todoItems.concat(result); + this.newTodoText = null; + }); + } + + delete(id: string): void { + this.todoService.delete(id).subscribe(() => { + this.todoItems = this.todoItems.filter(item => item.id !== id); + this.toasterService.info('Deleted the todo item.'); + }); + } +} +``` + +We've used `TodoService` to get the list of todo items and assigned the returning value to the `todoItems` array. We've also added `create` and `delete` methods. These methods will be used on the view side. + +### home.component.html + +Open the `/angular/src/app/home/home.component.html` file and replace its content with the following code block: + +````html +
    +
    +
    +
    TODO LIST
    +
    +
    + +
    +
    +
    + +
    +
    +
    + +
    +
    + +
      +
    • + {%{{{ todoItem.text }}}%} +
    • +
    +
    +
    +
    +```` + +### home.component.scss + +As the final touch, open the `/angular/src/app/home/home.component.scss` file and replace its content with the following code block: + +````css +#TodoList{ + list-style: none; + margin: 0; + padding: 0; +} + +#TodoList li { + padding: 5px; + margin: 5px 0px; + border: 1px solid #cccccc; + background-color: #f5f5f5; +} + +#TodoList li i +{ + opacity: 0.5; +} + +#TodoList li i:hover +{ + opacity: 1; + color: #ff0000; + cursor: pointer; +} +```` + +This is a simple styling for the todo page. We believe that you can do much better :) + +Now, you can run the application again to see the result. + {{end}} ## Conclusion From 456afa8c3a16c7cba670c214b7865c5eb381df84 Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Sat, 21 May 2022 12:14:27 +0300 Subject: [PATCH 7/7] Update Index.md --- docs/en/Tutorials/Todo/Single-Layer/Index.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/en/Tutorials/Todo/Single-Layer/Index.md b/docs/en/Tutorials/Todo/Single-Layer/Index.md index 244b30acb9..9f4927f5e4 100644 --- a/docs/en/Tutorials/Todo/Single-Layer/Index.md +++ b/docs/en/Tutorials/Todo/Single-Layer/Index.md @@ -348,10 +348,10 @@ Open the `Index.cshtml` file in the `Pages` folder and replace it with the follo @model TodoApp.Pages.IndexModel @section styles { - + } @section scripts { - + }
    @@ -391,9 +391,9 @@ We are using ABP's [card tag helper](../../UI/AspNetCore/Tag-Helpers/Cards.md) t This page imports a CSS and a JavaScript file, so we should also create them. -### Index.js +### Index.cshtml.js -Create an `Index.js` file in the `Pages` folder and add the following content: +Open the `Index.cshtml.js` file in the `Pages` folder and replace with the following content: ````js $(function () { @@ -430,9 +430,9 @@ In the second part, we created a new todo item on the server. If it succeeded, w The interesting part here is how we communicate with the server. See the [*Dynamic JavaScript Proxies & Auto API Controllers*](#dynamic-javascript-proxies--auto-api-controllers) section to understand how it works. But now, let's continue and complete the application. -### Index.css +### Index.cshtml.css -As for the final touch, create the `Index.css` file in the `Pages` folder and add the following content: +As for the final touch, open the `Index.cshtml.css` file in the `Pages` folder and replace with the following content: ````css #TodoList{ @@ -467,9 +467,9 @@ Now, you can run the application again and see the result. ### Dynamic JavaScript Proxies & Auto API Controllers -In the `Index.js` file, we've used the `todoApp.services.todo.delete(...)` and `todoApp.services.todo.create(...)` functions to communicate with the server. These functions are dynamically created by the ABP Framework, thanks to the [Dynamic JavaScript Client Proxy](../../../UI/AspNetCore/Dynamic-JavaScript-Proxies.md) system. They perform HTTP API calls to the server and return a promise, so you can register a callback to the `then` function as we've done above. +In the `Index.cshtml.js` file, we've used the `todoApp.services.todo.delete(...)` and `todoApp.services.todo.create(...)` functions to communicate with the server. These functions are dynamically created by the ABP Framework, thanks to the [Dynamic JavaScript Client Proxy](../../../UI/AspNetCore/Dynamic-JavaScript-Proxies.md) system. They perform HTTP API calls to the server and return a promise, so you can register a callback to the `then` function as we've done above. -> **services** keyword comes from the namespace (`namespace TodoApp.Services;`). +> **services** keyword comes from the namespace (`namespace TodoApp.Services;`). It's a naming convention. However, you may notice that we haven't created any API Controllers, so how does the server handle these requests? This question brings us to the [Auto API Controller](../../../API/Auto-API-Controllers.md) feature of the ABP Framework. It automatically converts the application services to **API Controllers** by convention.