Skip to content

Commit 375fbac

Browse files
committed
Tested for ABP v0.3.2. Also commented codes.
1 parent 5316afe commit 375fbac

File tree

194 files changed

+17552
-16114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+17552
-16114
lines changed

SimpleTaskSystem/SimpleTaskSystem.Application/DtoMappings/DtoMapping.cs renamed to SimpleTaskSystem/SimpleTaskSystem.Application/DtoMappings.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using SimpleTaskSystem.Tasks;
55
using SimpleTaskSystem.Tasks.Dtos;
66

7-
namespace SimpleTaskSystem.DtoMappings
7+
namespace SimpleTaskSystem
88
{
9-
internal static class DtoMapping
9+
internal static class DtoMappings
1010
{
1111
public static void Map()
1212
{
13+
//This code configures AutoMapper to auto map between Entities and DTOs.
14+
1315
Mapper.CreateMap<Task, TaskDto>();
1416
Mapper.CreateMap<Person, PersonDto>();
1517
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Simple task system - Application (service) layer.
2+
-----------------------------------------
3+
4+
This layer contains application services and DTOs. Application layer is used by presentation layer and uses domain (core) layer to perform application specific operations.

SimpleTaskSystem/SimpleTaskSystem.Application/SimpleTaskSystem.Application.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33-
<Reference Include="Abp, Version=0.3.1.2, Culture=neutral, processorArchitecture=MSIL">
33+
<Reference Include="Abp, Version=0.3.1.3, Culture=neutral, processorArchitecture=MSIL">
3434
<SpecificVersion>False</SpecificVersion>
35-
<HintPath>..\packages\Abp.0.3.1.2\lib\net451\Abp.dll</HintPath>
35+
<HintPath>..\packages\Abp.0.3.1.3\lib\net451\Abp.dll</HintPath>
3636
</Reference>
37-
<Reference Include="Abp.Application, Version=0.3.1.2, Culture=neutral, processorArchitecture=MSIL">
37+
<Reference Include="Abp.Application, Version=0.3.1.3, Culture=neutral, processorArchitecture=MSIL">
3838
<SpecificVersion>False</SpecificVersion>
39-
<HintPath>..\packages\Abp.Application.0.3.1.2\lib\net451\Abp.Application.dll</HintPath>
39+
<HintPath>..\packages\Abp.Application.0.3.1.3\lib\net451\Abp.Application.dll</HintPath>
4040
</Reference>
4141
<Reference Include="AutoMapper, Version=3.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
4242
<SpecificVersion>False</SpecificVersion>
@@ -78,7 +78,7 @@
7878
<Reference Include="System.Xml" />
7979
</ItemGroup>
8080
<ItemGroup>
81-
<Compile Include="DtoMappings\DtoMapping.cs" />
81+
<Compile Include="DtoMappings.cs" />
8282
<Compile Include="People\Dtos\GetAllPeopleOutput.cs" />
8383
<Compile Include="People\Dtos\PersonDto.cs" />
8484
<Compile Include="People\IPersonAppService.cs" />
@@ -96,6 +96,7 @@
9696
<ItemGroup>
9797
<None Include="app.config" />
9898
<None Include="packages.config" />
99+
<None Include="README.md" />
99100
</ItemGroup>
100101
<ItemGroup>
101102
<ProjectReference Include="..\SimpleTaskSystem.Core\SimpleTaskSystem.Core.csproj">

SimpleTaskSystem/SimpleTaskSystem.Application/SimpleTaskSystemApplicationModule.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
using Abp.Dependency;
44
using Abp.Modules;
55
using Abp.Startup;
6-
using SimpleTaskSystem.DtoMappings;
76

87
namespace SimpleTaskSystem
98
{
9+
/// <summary>
10+
/// 'Aplication layer module' for this project.
11+
/// </summary>
1012
public class SimpleTaskSystemApplicationModule : AbpModule
1113
{
14+
/// <summary>
15+
/// We declare depended modules explicitly.
16+
/// </summary>
1217
public override Type[] GetDependedModules()
1318
{
1419
return new[]
@@ -20,8 +25,12 @@ public override Type[] GetDependedModules()
2025
public override void Initialize(IAbpInitializationContext initializationContext)
2126
{
2227
base.Initialize(initializationContext);
28+
29+
//This code is used to register classes to dependency injection system for this assembly using conventions.
2330
IocManager.Instance.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
24-
DtoMapping.Map();
31+
32+
//We must declare mappings to be able to use AutoMapper
33+
DtoMappings.Map();
2534
}
2635
}
2736
}

SimpleTaskSystem/SimpleTaskSystem.Application/Tasks/Dtos/TaskDto.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace SimpleTaskSystem.Tasks.Dtos
55
{
6+
/// <summary>
7+
/// A DTO class that can be used in various application service methods when needed to send/receive Task objects.
8+
/// </summary>
69
public class TaskDto : EntityDto<long>
710
{
811
public int AssignedPersonId { get; set; }

SimpleTaskSystem/SimpleTaskSystem.Application/Tasks/Dtos/UpdateTaskInput.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55

66
namespace SimpleTaskSystem.Tasks.Dtos
77
{
8+
/// <summary>
9+
/// This DTO class is used to send needed data to <see cref="ITaskAppService.UpdateTask"/> method.
10+
///
11+
/// Implements <see cref="IInputDto"/>, thus ABP applies standard input process (like automatic validation) for it.
12+
/// Implements <see cref="ICustomValidate"/> for additional custom validation.
13+
/// </summary>
814
public class UpdateTaskInput : IInputDto, ICustomValidate
915
{
10-
[Range(1, long.MaxValue)]
16+
[Range(1, long.MaxValue)] //Data annotation attributes work as expected.
1117
public long TaskId { get; set; }
1218

1319
public int? AssignedPersonId { get; set; }
1420

1521
public TaskState? State { get; set; }
1622

23+
//Custom validation method. It's valled by ABP after data annotation validations.
1724
public void AddValidationErrors(List<ValidationResult> results)
1825
{
1926
if (AssignedPersonId == null && State == null)

SimpleTaskSystem/SimpleTaskSystem.Application/Tasks/ITaskAppService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33

44
namespace SimpleTaskSystem.Tasks
55
{
6+
/// <summary>
7+
/// Defines an application service for <see cref="Task"/> operations.
8+
///
9+
/// It extends <see cref="IApplicationService"/>.
10+
/// Thus, ABP enables automatic dependency injection, validation and other benefits for it.
11+
///
12+
/// Application services works with DTOs (Data Transfer Objects).
13+
/// Service methods gets and returns DTOs.
14+
/// </summary>
615
public interface ITaskAppService : IApplicationService
716
{
817
GetTasksOutput GetTasks(GetTasksInput input);
18+
919
void UpdateTask(UpdateTaskInput input);
20+
1021
void CreateTask(CreateTaskInput input);
1122
}
1223
}

SimpleTaskSystem/SimpleTaskSystem.Application/Tasks/TaskAppService.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,51 @@
66

77
namespace SimpleTaskSystem.Tasks
88
{
9+
/// <summary>
10+
/// Implements <see cref="ITaskAppService"/> to perform task related application functionality.
11+
///
12+
/// Inherits from <see cref="ApplicationService"/>.
13+
/// <see cref="ApplicationService"/> contains some basic functionality common for application services (such as logging and localization).
14+
/// </summary>
915
public class TaskAppService : ApplicationService, ITaskAppService
1016
{
17+
// These members set in constructor using constructor injection.
18+
1119
private readonly ITaskRepository _taskRepository;
1220
private readonly IPersonRepository _personRepository;
13-
21+
22+
/// <summary>
23+
///In constructor, we can get needed classes/interfaces.
24+
///They are sent here by dependency injection system automatically.
25+
/// </summary>
1426
public TaskAppService(ITaskRepository taskRepository, IPersonRepository personRepository)
1527
{
1628
_taskRepository = taskRepository;
1729
_personRepository = personRepository;
1830
}
19-
31+
2032
public GetTasksOutput GetTasks(GetTasksInput input)
2133
{
34+
//Called specific GetAllWithPeople of task repository.
2235
var tasks = _taskRepository.GetAllWithPeople(input.AssignedPersonId, input.State);
36+
37+
//Used AutoMapper to automatically convert List<Task> to List<TaskDto>.
2338
return new GetTasksOutput
2439
{
2540
Tasks = Mapper.Map<List<TaskDto>>(tasks)
2641
};
2742
}
28-
43+
2944
public void UpdateTask(UpdateTaskInput input)
3045
{
46+
//We can use Logger, it's defined in ApplicationService class.
3147
Logger.Info("Updating a task for input: " + input);
3248

49+
//Retrieving a task entity with given id using standard Get method of repositories.
3350
var task = _taskRepository.Get(input.TaskId);
3451

52+
//Updating changed peoperties of the retrieved task entity.
53+
3554
if (input.State.HasValue)
3655
{
3756
task.State = input.State.Value;
@@ -41,19 +60,26 @@ public void UpdateTask(UpdateTaskInput input)
4160
{
4261
task.AssignedPerson = _personRepository.Load(input.AssignedPersonId.Value);
4362
}
63+
64+
//We even do not call Update method of the repository.
65+
//Because an application service method is a 'unit of work' scope as default.
66+
//ABP automatically saves all changes when a 'unit of work' scope ends (without any exception).
4467
}
4568

4669
public void CreateTask(CreateTaskInput input)
4770
{
71+
//We can use Logger, it's defined in ApplicationService class.
4872
Logger.Info("Creating a new task with description: " + input.Description);
4973

74+
//Creating a new Task entity with given input's properties
5075
var task = new Task { Description = input.Description };
5176

5277
if (input.AssignedPersonId.HasValue)
5378
{
5479
task.AssignedPersonId = input.AssignedPersonId.Value;
5580
}
5681

82+
//Saving entity with standard Insert method of repositories.
5783
_taskRepository.Insert(task);
5884
}
5985
}

SimpleTaskSystem/SimpleTaskSystem.Application/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Abp" version="0.3.1.2" targetFramework="net451" />
4-
<package id="Abp.Application" version="0.3.1.2" targetFramework="net451" />
3+
<package id="Abp" version="0.3.1.3" targetFramework="net451" />
4+
<package id="Abp.Application" version="0.3.1.3" targetFramework="net451" />
55
<package id="AutoMapper" version="3.2.1" targetFramework="net451" />
66
<package id="Castle.Core" version="3.3.0" targetFramework="net451" />
77
<package id="Castle.Core-log4net" version="3.3.0" targetFramework="net451" />

SimpleTaskSystem/SimpleTaskSystem.Core/People/IPersonRepository.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
namespace SimpleTaskSystem.People
44
{
5+
/// <summary>
6+
/// Defines a repository to perform database operations for <see cref="Person"/> Entities.
7+
///
8+
/// Extends <see cref="IRepository{TEntity}"/> to inherit base repository functionality.
9+
/// </summary>
510
public interface IPersonRepository : IRepository<Person>
611
{
7-
12+
//We can add methods here those are specific to Person entities. Currently, we don't need it, base methods enough.
813
}
914
}

0 commit comments

Comments
 (0)