Skip to content

Instantly share code, notes, and snippets.

@EspenBrun
Created August 22, 2019 12:45
Show Gist options
  • Select an option

  • Save EspenBrun/b453721d3b391da171201bb756496d00 to your computer and use it in GitHub Desktop.

Select an option

Save EspenBrun/b453721d3b391da171201bb756496d00 to your computer and use it in GitHub Desktop.

Revisions

  1. EspenBrun created this gist Aug 22, 2019.
    99 changes: 99 additions & 0 deletions Platform.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    using System;
    using System.Net.Http;

    namespace Platform
    {
    // the platform controls the dependency injection
    // External world calls internal-api/create-invoice
    // A internal-api can call a module-api
    // A module-api can not call another module-api
    // If a module-api needs to call another package/microservice, it needs to specify the interface in its Client Library

    // In this case, let HEM and ServiceProvider be packages in the same monolith
    // Communications is a microservice, extracted due to high load (that's when we extract)
    // So HEM httpcall to communication, and internal call to serviceProvider. So saved a httpcall to serviceprovider
    // Scalability: faster, and if service provider is slow, we do not hog resources in communication
    public class Platform
    {
    internal class PlatformMain
    {
    public void main(string[] args)
    {
    new Hem();
    new ServiceProvider();
    }
    }

    internal class Hem
    {
    private CommunicationLibrary.ICommunications Communications { get; set; }
    private CommunicationLibrary.ISPDepend SpDepend { get; set; }

    private IServiceProvider ServiceProvider { get; set; }

    public void CreateInvoice(CreateInvoiceDto dto)
    {
    Communications.SendMessage(dto.ServiceCenterId, SpDepend);
    ServiceProvider.employ(dto.ServiceCenterId);
    }
    }

    internal class Communication
    {
    // module endpoints
    public void sendMessage(string dtoServiceCenterId, string employeeName)
    {

    }
    }

    internal class CommunicationLibrary
    {
    internal class CommunicationClient : ICommunications
    {
    public void SendMessage(string dtoServiceCenterId, ISPDepend spDepend)
    {
    var employeeName = spDepend.GetEmployeeName(Guid.Empty);
    var httpClient = new HttpClient();
    var getEmployeeDto = new GetEmployeeDto
    {
    ServieCenterId = dtoServiceCenterId,
    EmployeeName = employeeName
    };
    httpClient.PostAsync(getEmployeeDto.ToString(), new MultipartContent());
    }
    }

    public interface ISPDepend
    {
    string GetEmployeeName(Guid employeeId);
    string GetPositionName(Guid employeeId);
    }

    internal interface ICommunications
    {
    void SendMessage(string dtoServiceCenterId, ISPDepend spDepend);
    }
    }

    internal interface IServiceProvider
    {
    void employ(string dtoServiceCenterId);
    }
    }

    internal class ServiceProvider
    {
    }

    internal class CreateInvoiceDto
    {
    public string ServiceCenterId;
    }

    internal class GetEmployeeDto
    {
    public string ServieCenterId { get; set; }
    public string EmployeeName { get; set; }
    }
    }