Continue the previous article How to create a simple Investiment API NET Core 6 for tranning Part.1, now we need to do this for separate our project in layers:
*Repository
*Services
*Response classes
*And injection dependencies
Creating the Response class
Inside the folder Response, I created the classe as shown in the image below.
Creating the Repository class
Inside the folder Data -> Repository, I created the class repositories and your interfaces. Before I created the interfaces, as show image bellow.
For now I just created one method GET, but the plan is I'll create the anothers methods, POST and PUT. In repository, we have the class as how image bellow. Notice that I used the mocky JSON that I created earlier.
Configure the injection dependency
I like the separate responsibility, for example, I could have put this injection dependency directly in the class Program, but to make the organization better my code, I thought it was better to separate it. So, I created the class DependencyInjectionRegistry and here I have an only static void method that receives the IServiceCollection.
Creating the Services class
Here I created the services classes, the service is called the repository class. I injected the dependency into the constructor. In this class I have put the business rules, in future I will create the unit test for this roles.
The service InvestmentServices return all investment in Investment Portfolio the client.
Creating Controllers and endpoints
I a created only controller is InvestmentController. Here our API has an everything about the investment client.
So this is a simple idea for the API, I will create the other version using VSCode, and finish the unit test. I hope that help you, and you can get the repository in URL bellow.
Github project: https://github.com/JessicaNathany/api-fanfareInvest
Top comments (0)