How to create a simple Investiment API NET Core 6 for tranning Part.2
Tags: dotnet, api, core, webdev
Published: 2022-07-04 12:04:13

Continue the previous article [How to create a simple Investiment API NET Core 6 for tranning Part.1](https://dev.to/jessicanathany/how-to-create-a-simple-investiment-api-net-core-6-for-tranning-part1-5819), 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04dygr4hcv224zfrh29b.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xs9va3l7rcg80n7r5fh.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qvbtijnh1tprrj7r8jo.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iu3i5saf6hs0iy281l9m.png)
    
  

###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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02w6ftslb3kqlyq890aa.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lanbhik9hdhq2mrqti3t.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0r495sgouzj5b9cly478.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2z3wiv8a5514wgju8x0i.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5d5tx9fsvth9tdwb2vhg.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qax0urwx8zkh6o2t4eor.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rtl5cjdj549rj3sl8ci.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5a228ovo9fx7r86ks06l.png)
   

###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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lm9f2660uh7phvqjbghz.png)

 
###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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26kuj2tdys6d2wnl5bju.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pq75ntgvlj2se9acf210.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3z8z561qcatxmij2gsxt.png)
   

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ov778l3hzluuf9e3i6l4.png)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhbf22w5yh3lqfc7yp8x.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sk71mkskpfqqmd72x8bo.png)
 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/en5rr9qlyumcrage16nx.png)
 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ioc2fw3c7a34n4q7mqr0.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dro82j1xl726xm7ro51p.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clwog1y4yqni76g0wpz7.png)

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