Home > Net >  Ingest data into Microservice application
Ingest data into Microservice application

Time:09-29

I'm building a microservice application which should mimic an online Webshop, and I have built some basic components to see how they how well the services communicate.

I however am having a very annoying problem. Whenever I start the application in Microsoft Visual Studio, the microservices which are required to have data, f.ex. Products I have to manually add products with HTTP requests whenever I want to test some new features in my application. Is there any way to have the service ingest some data from a csv, JSON or database when the application is built? I have tried to research this matter, but haven't been able to find any way to ingest data to the services. How should this task be approached, and does there exists some smart techniques to accomplish this?

CodePudding user response:

I m not very keen on azure development and am missing a few bits and pieces to really understand your issue (e.g. where you are storing the products when manually adding them). but you should always be able to add some testing data in form of e.g. a json file and deserialize the contents on startup. for clarification, lets say you got an class attribute which stores a list of products (in this example just strings).

public static List<string> Products = new List<string>();

you could use something like this in your startup:

Controller.Products = JSonSerializer.Deserialize<List<string>(File.ReadAllText(testdata.json));

in this example the contents of your json file would look something like this:

[ "Chair", "Table", "Carpet", "Computer" ]

hope this helps you! please let me know i m missing the point here or if i could answer your question :)

  • Related