Table of Contents
API reference

Method AddDiscordHostedService

Namespace
DisCatSharp.Hosting.DependencyInjection
Assembly
DisCatSharp.Hosting.DependencyInjection.dll

AddDiscordHostedService<TService>(IServiceCollection)

Adds your bot as a BackgroundService, registered in Dependency Injection as TService

public static IServiceCollection AddDiscordHostedService<TService>(this IServiceCollection services) where TService : class, IDiscordHostedService

Parameters

services IServiceCollection

Returns

IServiceCollection

Reference to services for chaining purposes

Type Parameters

TService

Remarks

IDiscordHostedService is scoped to ServiceLifetime.Singleton.
Maps to Implementation of TService

AddDiscordHostedService<TInterface, TService>(IServiceCollection)

Add TService as a background service which derives from TInterface and IDiscordHostedService

public static IServiceCollection AddDiscordHostedService<TInterface, TService>(this IServiceCollection services) where TInterface : class, IDiscordHostedService where TService : class, TInterface, IDiscordHostedService

Parameters

services IServiceCollection

Returns

IServiceCollection

Reference to services for chaining purposes

Type Parameters

TInterface

Interface which TService inherits from

TService

Your custom bot

Remarks

To retrieve your bot via Dependency Injection you can reference it via TInterface