Skip to content

Brokers

Hassan Rezk Habib edited this page Nov 24, 2020 · 7 revisions

Brokers

Introduction

Brokers play the role of a liaison between the business logic and the outside world. They are wrappers around any external libraries, resources or APIs to satisfy a local interface for the business to interact with these resources without having to be tightly coupled with any particular resources or external library implementation.

Brokers in general are meant to be disposable and replaceable - they are built with the understanding that technology evolves and changes all the time and therefore they shall be at some point in time in the lifecycle of a given application be replaced with a modern technology that gets the job done faster.

But Brokers also ensure that your business is pluggable by abstracting away any specific externa<l resource dependencies from what you software is actually trying to accomplish.

Implementation

For instance, when we build storage brokers - we maintain a generic contract for all CRUD operations as follows:

    public partial interface IStorageBroker
    {
        public ValueTask<Student> InsertStudentAsync(Student student);
        public IQueryable<Student> SelectAllStudents();
        public ValueTask<Student> SelectStudentByIdAsync(Guid studentId);
        public ValueTask<Student> UpdateStudentAsync(Student student);
        public ValueTask<Student> DeleteStudentAsync(Student student);
    }
Clone this wiki locally