In microservice architecture, how does Constants get passed around and used in the different APIs?
I.e,
- Microservice 1
- Microservice 2 ...
- Microservice N
// Constants
public const string CONSTANT1 = "xxx";
...
Where do we put this constant? Do we just create an API that serves all these constant and have other API connect to it to consume it or but it in a separate project and reference it?
How does frontend JS consume the constant in the C# files then?
Top comments (1)
Ok, this doesn't have a simple answer, so I'll try to aim to the one that may be the more common one.
If you have constants that represent something, and you need that representation in more than one .Net microservice, I would say: Create a Nuget package with them and consume said Nuget package in the microservices in need of the constants.
This Nuget concept not only applies to constant, but to common code. For example, it will be 99% probable that you will need models shared among microservices. I recommend creating a Nuget to encapsulate all public models. Just the public models that are needed in more than one microservice.
As for the last part of your question, I don't understand. If you need a constant, do you really need a backend web server to transmit them?