Table of Contents

Register additional services

In your business assemblies (Domain or Application layer), you can register additional services by creating a Startup.cs file.

Startup class

The framework automatically discovers and calls the ConfigureServices method at startup if the file exists.

Important

Discovery requirements:

  • The file must be named Startup.cs and located at the root of the project
  • The class must be named Startup and be in the root namespace of the assembly
  • The method must be public static void ConfigureServices(IServiceCollection services)
public static class Startup
{
    public static void ConfigureServices(IServiceCollection services)
    {
        services.AddScoped<IMyService, MyService>();
    }
}

This method is called by both the BackEnd and the TaskRunner.

Host-specific startup classes

In the Application layer, you can register services for a specific host by creating dedicated startup files. These classes receive an additional IConfiguration parameter.

Note

Host-specific startup classes are only supported in the Application layer.

Host File name Class name
BackEnd only BackEndStartup.cs BackEndStartup
TaskRunner only TaskRunnerStartup.cs TaskRunnerStartup

BackEnd-only services

Create a BackEndStartup.cs file to register services that should only be available in the web host:

public static class BackEndStartup
{
    public static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        // Registrations only for the web host
    }
}

TaskRunner-only services

Create a TaskRunnerStartup.cs file to register services that should only be available in the task runner:

public static class TaskRunnerStartup
{
    public static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        // Registrations only for the task runner
    }
}