Click here to Skip to main content
16,022,205 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello everyone,
May I have some advice for my demo microservice project?
//Only the getAll() API and the Eureka config so far

GitHub - HunglnSE161586/OrderService: Order microservice test[^]

//I currently store some data in appsettings.json, so some tips for that would be nice too. Oh, and ignore the default C# controller.

What I have tried:

The link below is the image of my database, do you have any suggestions?
https://github.com/HunglnSE161586/OrderService/blob/main/Screenshot%202024-10-08%20142049.png[^]
Posted
Updated 7-Oct-24 22:29pm
Comments
Rob Philpott 8-Oct-24 9:12am    
Well, first thing I notice is all the obj/bin/.vs folders in source control. My first recommendation would be to get a .gitignore file set up so that doesn't happen. You just want your source files, project files, solution files etc. - not all the output files which are generated from those.
Hung Le Nguyen 8-Oct-24 9:16am    
ah, that's my bad. I copy the whole project folder, paste it to the GitHub folder, and then push it.

1 solution

Some thoughts. In OrderRepository[^] you instantiate the OrderServiceContract, so that will hit the default constructor. However, OrderServiceContract has a parameterised constructor which accepts the DbContext; you need that to hit your DbSet (Orders).

The calls that I have looked at appear to be synchronous. Do you really want all your database access to be synchronous, or would you rather use async/await with the appropriate EF extensions?

The only time I've seen people using Impl at the name of a class is in Java. The common C# convention is to name the interface ISomething, and the implementation is the same without the I at the start (e.g. Something).

On the subject of interfaces. Do you really need an interface? I know that it's something we see in C# examples but, in most cases, interfaces are unnecessary. There are, generally, other ways to accomplish what you see in the interface. Interestingly, you don't even need an interface to register a class in for dependency injection.
 
Share this answer
 
Comments
Hung Le Nguyen 8-Oct-24 9:11am    
Since my main language is Java, I'm not very good at C#. Therefore, I just write as closely as I usually do in Java. And I want the DB to be async/await, but I don't know how so I use this for now. Would you like to show me how to do it?
Pete O'Hanlon 8-Oct-24 9:21am    
Have a look at this to get an idea. https://learn.microsoft.com/en-us/ef/ef6/fundamentals/async
Hung Le Nguyen 8-Oct-24 9:37am    
I see, thanks for the source. Do you have any project recommendations I can look up on GitHub to use as an example for this and how I should write my repository, service, and API in general? Thanks again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900