Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Install Liquid project templates

Gustavo Denis edited this page Oct 31, 2019 · 1 revision
Main > Using Liquid for building your application > Install Liquid project templates

Segregate operations that read data from operations that update data by using separate interfaces. This can maximize performance, scalability, and security. Supports the evolution of the system over time through higher flexibility, and prevents update commands from causing merge conflicts at the domain level.

Liquid is built using the pattern Command and Query Responsibility Segregation (CQRS) that segregates the operations that read data (queries) from the operations that update data (commands) by using separate interfaces.

##CRUD

CRUD operations are applied to the same representation of the entity. The same entity is used for both the read and write operations. 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>();

        ...
    }
}

##CQRS

Using a different model to update information than the model you use to read information.. For some situations, this separation can be valuable, but beware that for most systems CQRS adds risky complexity. 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);        
    }
}

##CQRS and Service Bus

##REST and Service Bus

[Authorize]
        [Queue("hotel",1)]
        public void DeliverNewHotel(HotelsMessage hotelsMessage)
        { 
            ValidateInput(hotelsMessage);
            //Calls domain (business) logic
            var response = Factory<ReviewsService>().IsHotelValid(hotelsMessage.hotelVM.Id);

            //Terminates the message according to domain response
            Terminate(response);
        }
Use this PoC sample code as your starting point

Clone this wiki locally