Search code examples
c#asp.net-web-apimicroservices

Microservices communication message templates approach


I try to realize microservice-based project on ASP.NET Core (Web API). So, I have an independent components which communicate between them and external world. So, I have "connection points" between services - view model (input data) of one is an equvivalent for request/response for others and so on. I think, there are some best practices for this case which allow me not to create tonnes of identically code, am I right?

Deeply, let's look at the situation, where I have, for example, data in the database, and microservice, which get (possible transform or wide a little) an information from DB and give it to an asker. Is it possible not to create duplicate code for storing and responsing information from database?

Thank you.


Solution

  • What are you talking about are models. Input models and output models (DTOs).

    If your projects are part of the same solution, then you can probably have a shared project or class library, to reuse your models.

    If not, create a NuGet package, distribute it via your own feed and use it in all the projects that require it.

    In order for this to work, you need to keep this project very simple. It should not have any dependencies preferably, so you can reference it without unintended consequences. If you keep it very simple then it can work well.