DEV Community

Jéssica Nathany
Jéssica Nathany

Posted on

3 1

How to create a simple Investiment API NET Core 6 for tranning Part.2

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.

Image description

Image description

Image description

Image description

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.

Image description

Image description

Image description

Image description

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.

Image description

Image description

Image description

Image description

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.

Image description

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.

Image description

Image description

Image description

Image description

Image description

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.

Image description

Image description

Image description

Image description

Image description

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

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay