Skip to content

Adding Something New

zysim edited this page May 24, 2022 · 10 revisions

This describes the steps you need for adding (and editing) classes in the main project (LeaderboardBackend).

Always remember to run dotnet format style and dotnet format whitespace in solution root before pushing commits. Alternatively, refer to our style guide.

From here on, we assume you're in the main project.

Todos

  • Add a page for tests

Adding A Model

  1. Create the model in Models/Entities/
  2. Add a DbSet of the model in Models/Entities/ApplicationContext.cs
    • Add any default values, if needed, in OnModelCreating
  3. Create a new migration with the ef CLI tool:
    dotnet ef migrations add -c ApplicationContext Create<ModelName>
    • This creates a file in Migrations
    • You can migrate locally with dotnet ef database update -c ApplicationContext

Editing A Model

  1. Make your changes
  2. Create a new migration:
    dotnet ef migrations add -c ApplicationContext <ModelName>_<ChangeSummary>

Adding A Controller

  1. Create the controller in Controllers/

Adding A Service

  1. Create an interface for the service in Services/
  2. Create its implementation in Services/Impl/
  3. Add the service to Program.cs:
    // Program.cs
    
    // ...
    builder.Services.AddScoped<IJudgementService, JudgementService>();
    builder.Services.AddScoped<IRunService, RunService>();
    builder.Services.AddScoped<INewService, NewService>(); // The new service

This allows controllers to call services via dependency injection in the their constructors.

Clone this wiki locally