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

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 👀

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay