From 9b866be70efcbca6f43d2d10536594bf3090c583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 3 Apr 2020 15:09:25 +0300 Subject: [PATCH] Update Application-Services.md --- docs/en/Application-Services.md | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/docs/en/Application-Services.md b/docs/en/Application-Services.md index da22479593..f7f7675f46 100644 --- a/docs/en/Application-Services.md +++ b/docs/en/Application-Services.md @@ -132,6 +132,8 @@ The `CreateAsync` method above manually creates a `Book` entity from given `Crea However, in many cases, it's very practical to use **auto object mapping** to set properties of an object from a similar object. ABP provides an [object to object mapping](Object-To-Object-Mapping.md) infrastructure to make this even easier. +Object to object mapping provides abstractions and it is implemented by the [AutoMapper](https://automapper.org/) library by default. + Let's create another method to get a book. First, define the method in the `IBookAppService` interface: ````csharp @@ -158,7 +160,7 @@ public class BookDto } ```` -we creating a [Profile](https://docs.automapper.org/en/stable/Configuration.html#profile-instances) class. Example: +AutoMapper requires to create a mapping [profile class](https://docs.automapper.org/en/stable/Configuration.html#profile-instances). Example: ````csharp public class MyProfile : Profile @@ -187,22 +189,10 @@ public class MyModule : AbpModule } ```` -`AddMaps` registers all profile classes defined in the assembly of the given class, typically your module class. It also registers for the [attribute mapping](https://docs.automapper.org/en/stable/Attribute-mapping.html). For more information, please refer to the [object to object mapping](Object-To-Object-Mapping.md) document. +`AddMaps` registers all profile classes defined in the assembly of the given class, typically your module class. It also registers for the [attribute mapping](https://docs.automapper.org/en/stable/Attribute-mapping.html). Then you can implement the `GetAsync` method as shown below: -````csharp -public async Task GetAsync(Guid id) -{ - var book = await _bookRepository.GetAsync(id); - return book.MapTo(); -} -```` - -`MapTo` extension method converts `Book` object to `BookDto` object by copying all properties with the same naming. - -An alternative to the `MapTo` is using the `IObjectMapper` service: - ````csharp public async Task GetAsync(Guid id) { @@ -211,8 +201,6 @@ public async Task GetAsync(Guid id) } ```` -While the second syntax is a bit harder to write, it better works if you write unit tests. - See the [object to object mapping document](Object-To-Object-Mapping.md) for more. ## Validation