-
Notifications
You must be signed in to change notification settings - Fork 13
Structure internal logic
| Main > Using Liquid for building your application > Structure internal logic |
|---|
After defining the external interfaces of the microservice (i.e. its APIs), the next step is to structure its internal logic according to the pattern of choice.
| Take a look at related key concepts of Liquid |
|---|
| Encapsulated Domain Logic |
| Business Error Handling |
#Use CRUD pattern CRUD microservices are structured around its persisted data entities and are derived from a Object-Oriented design.
Liquid provides a way to do that using a collaboration of classes derived from LightService base class as the example bellow:
public class GoalService: LightService
{
public DomainResponse GetByName(string titleTip)
{
var data = Repository.GetAsync<GoalModel>(g => g.Title.Contains(titleTip)).Result;
return Response(data);
}
public async Task<DomainResponse> Update(string departmentId, GoalViewModel goalVM)
{
GoalModel goal = new GoalModel();
goal.MapFrom(goalVM);
goal.departmentId = departmentId;
goal = FactoryDelegate<AprovalService>().PrepareAprovers(goal);
...
Repository.AddOrUpdateAsync(goal);
return Response();
}
}
public class AprovalService: LightService
{
public GoalModel PrepareAprovers(GoalModel goal)
{
goal.Aprovers = new List<AproverModel>();
...
}
}
| See how this is done in Liquid Hotel360 sample application. |
|---|
#Use CQRS pattern CQRS microservices are structured around their exposed functionality, i.e. the commands and queries they accept.
This type of internal design is on the spotlight lately even though it was widely recommended to be used with caution.
With that caution in mind, Liquid provides a light and easy way of doing such type of programming as the following sample code:
public class UpdateGoalCommand : LightCommand<UpdateGoalCommand>
{
public string goalId;
public string departmentId;
public double value;
public DateTime date;
...
}
}
public class UpdateGoalHandler : LightCommandHandler<UpdateGoalHandler>
{
protected override DomainResponse Handle()
{
GoalModel goal = new GoalModel();
goal.MapFrom(Command);
...
//Prepare aprrovers
goal.Aprovers = new List<AproverModel>();
...
var res = Repository.AddOrUpdateAsync(goal);
return Response(res);
}
}
| See how this is done in Liquid Hotel360 sample application. |
|---|