GithubHelp home page GithubHelp logo

pride7k / trackerapi Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 20.29 MB

RESTful API in .NET.

C# 96.95% JavaScript 3.05%
entity-framework-core aspnet-core hangfire-dotnet-core rest-api sqlite integration-testing

trackerapi's Introduction

TrackerApi

Still Working on

RestFul API with .NET Core

This project is just to test the knowledge with the .NET Core´s API and entity framework core concepts.

Which techs/patterns/frameworks are being used in the project?

  • C#
  • ASP NET Core
  • Entity Framework Core
  • Sql Lite
  • XUnit
  • JWT Authentication
  • Cache Store
  • Fluent Assertions
  • Polly Retry Policy
  • Unit Of Work
  • Circuit Breaker
  • Decorator Pattern
  • K6 API Loading Testing (Stress, Spike, Load, Soak)

How is it structured ?

MVCS Structure, but without the View since this project is not about frontend concepts.

The business layers can be find inside the services folder.

Database

Configurations about database it´s in the the AppDbContext.cs on the method OnConfiguring.

image

We can see that it´s configured to be cache shared. It´s because we in this way we can share the same cache in memory for every thread, reducing the numbers of connections in database.

We also can see the DbSet that are used to inform which classes are tables in our database.

Models

Each model represents a table in database, which each propertie represents a column.

image

Controllers

image

Here we have our controller named as "UserController" that in inherits from "ControllerBase". That´s because doing this we can use some return types such as BadRequest() or Ok() that help us to make a restful Api.

We can also see some Dependency injection.

image

That´s possible because it´s mapped in the Startup class.

image

It´s was choosed to use AddScoped because since the same instance keep´s from each web request, makes sense to use in a controller.

Backing to our controller we can see that we are calling our business layer by the variable called "_services" that it´s being populated by DI.

image

One cool thing that we can see in the image above is the routing.

As we can see we are doing routing in a different way, as an example, "skip:int". We could have done in the normal way such as [FromRoute] but doing in this way it´s forces the consumer to pass a value with the type that we are expecting. If the consumer passes a value such as string instead a int he is going to get a 404 error.

Services.cs

image

Here we have the IService interface that provides the methods, and the class that implements. We also have the folder called ViewModel, that has the DTO classes.

image Quick example of the interface

image

We can se in the image above that the class implements the interface and also has a DI.

Custom Errors

image

We have some classes for custom erros that we use to throw inside the business class to the controller layers.

What could be done to improve?

  • Unit of work
  • Repository Pattern
  • Better tests
  • Fluent Validation instead data annotation on models
  • Change DI AddScope dependencies to AddTransient
  • Better use of the SOLID principle
  • Clean Archiecture

How to Set up?

Clone the project where you want to save it

Open the solution

Go to the package manager console

Run the command

dotnet-ef database update

Run the command

nuget restore

Open cmd inside the TrackerApi Folder

Run the command

dotnet watch run

References

MVCS Shared Cache Sql Lite Dependency Injection Types of DI Data Annotation Xunit With Moq Xunit With Moq Moq MVC With Asp Net Core Relationships in Entity Framework Core More Relationships in Entity Framework Core Even More Relationships in Entity Framework Core

trackerapi's People

Contributors

pride7k avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.