Skip to content

Instantly share code, notes, and snippets.

@EspenBrun
Created August 22, 2019 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EspenBrun/b453721d3b391da171201bb756496d00 to your computer and use it in GitHub Desktop.
Save EspenBrun/b453721d3b391da171201bb756496d00 to your computer and use it in GitHub Desktop.
Microservice Monolith
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; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment