CojectCore.BackgroundServices 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package CojectCore.BackgroundServices --version 1.0.3
                    
NuGet\Install-Package CojectCore.BackgroundServices -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CojectCore.BackgroundServices" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CojectCore.BackgroundServices" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="CojectCore.BackgroundServices" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CojectCore.BackgroundServices --version 1.0.3
                    
#r "nuget: CojectCore.BackgroundServices, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CojectCore.BackgroundServices@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CojectCore.BackgroundServices&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=CojectCore.BackgroundServices&version=1.0.3
                    
Install as a Cake Tool

Copyright (c) 2024 Akwad Arabia

CojectCore.BackgroundServices

A lightweight and easy-to-use background service library for ASP.NET Core applications. Manage SMS, Email, and custom background tasks with simple configuration.

Features

Easy Integration - One line of code to enable background services
Configurable - Enable/disable services via appsettings.json
Extensible - Add custom background tasks easily
Logging Support - Built-in logging for all operations
Scoped Services - Proper dependency injection with scoped lifetimes

Installation

dotnet add package Coject.BackgroundServices

Or via NuGet Package Manager:

Install-Package Coject.BackgroundServices

Quick Start

1. Install the package

dotnet add package Coject.BackgroundServices

2. Configure appsettings.json

{
  "BackgroundService": {
    "EnabledServices": ["ServiceSMS", "ServiceMail"],
    "IntervalSeconds": 10
  }
}

3. Register in Program.cs

using Coject.BackgroundServices.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Register your core dependencies
builder.Services.AddScoped<CoreModuleDB>();
builder.Services.AddScoped<ApiContext>();

// Add background services with one line
builder.Services.AddCojectBackgroundServices(builder.Configuration);

var app = builder.Build();
app.Run();

4. Done! 🎉

Your background services will start automatically and run based on the configured interval.

Configuration

appsettings.json

Property Type Description Default
EnabledServices string[] Array of service names to enable []
IntervalSeconds int Interval between executions in seconds 60

Available Services

  • ServiceSMS - SMS message processing
  • ServiceMail - Email message processing

Examples

Run every 10 seconds:

{
  "BackgroundService": {
    "EnabledServices": ["ServiceSMS", "ServiceMail"],
    "IntervalSeconds": 10
  }
}

Enable only SMS:

{
  "BackgroundService": {
    "EnabledServices": ["ServiceSMS"],
    "IntervalSeconds": 30
  }
}

Disable all services:

{
  "BackgroundService": {
    "EnabledServices": [],
    "IntervalSeconds": 60
  }
}

Adding Custom Background Tasks

1. Create your task class

using Coject.BackgroundServices.Interfaces;

public class CustomBackgroundTask : IBackgroundTask
{
    private readonly ILogger<CustomBackgroundTask> _logger;
    
    public string ServiceName => "ServiceCustom";
    
    public CustomBackgroundTask(ILogger<CustomBackgroundTask> logger)
    {
        _logger = logger;
    }
    
    public async Task ExecuteAsync(CancellationToken cancellationToken)
    {
        _logger.LogInformation("Custom task executing...");
        // Your logic here
    }
}

2. Register it

builder.Services.AddCojectBackgroundServices(builder.Configuration);
builder.Services.AddBackgroundTask<CustomBackgroundTask>();

3. Enable in appsettings.json

{
  "BackgroundService": {
    "EnabledServices": ["ServiceSMS", "ServiceMail", "ServiceCustom"],
    "IntervalSeconds": 10
  }
}

Requirements

  • .NET 6.0 or higher
  • ASP.NET Core

Dependencies

Your main project must register these dependencies before calling AddCojectBackgroundServices():

builder.Services.AddScoped<CoreModuleDB>();
builder.Services.AddScoped<ApiContext>();

Logging

The package uses ILogger for all logging. Configure your logging in appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Coject.BackgroundServices": "Debug"
    }
  }
}

License

MIT License - see LICENSE.txt for details

Support

For issues, questions, or contributions, please visit:

Changelog

Version 1.0.0

  • Initial release
  • SMS background service
  • Email background service
  • Configurable intervals
  • Enable/disable services via configuration
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 313 11/13/2025
1.0.5 275 11/12/2025
1.0.4 280 11/11/2025
1.0.3 280 11/11/2025
1.0.2 118 11/8/2025

Initial release with SMS and Email background services support.