WeTools.WorkerService 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package WeTools.WorkerService --version 1.0.1
NuGet\Install-Package WeTools.WorkerService -Version 1.0.1
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="WeTools.WorkerService" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WeTools.WorkerService --version 1.0.1
#r "nuget: WeTools.WorkerService, 1.0.1"
#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.
// Install WeTools.WorkerService as a Cake Addin
#addin nuget:?package=WeTools.WorkerService&version=1.0.1

// Install WeTools.WorkerService as a Cake Tool
#tool nuget:?package=WeTools.WorkerService&version=1.0.1

WeTools.WorkerService

.Net core Worker Service 扩展库,目的为更易控制每一个worker 的运行。

提供根据配置文件对每一个Worker的停止、启动和自动解析注册Worker。

获取配置的方式不限于 使用配置文件,也可以使用数据库,也可以使用 [WeTools.SqlSugarDBConfigProvider](NuGet Gallery | WeTools.SqlSugarDBConfigProvider 1.0.0) nuget包,读取数据库配置。

未来计划 增加一个轻量级的服务配置中心,更方便的管理服务。

方式1,worker 类型通过配置文件解析

  1. 在配置文件添加节点
"WeTools": {
    "Dir": "/", //worker 所在文件夹, 根目录为 / ;
    "Workers": [
      {
        "Name": "Worker2",
        "WorkerName": "Worker2",//具体的实现类名
        "Enable": true //此节点控制worker 的运行
      },
      {
        "Name": "Worker",
        "WorkerName": "Worker",
        "Enable": true
      }

    ]
  }
  1. 新建worker,并继承WeToolBackgroundService。

  2. 在Program类 ConfigureServices 里注册服务

services.AddServiceOptions(hostContext);
services.UseWorkers();

方式2 worker 通过特性解析

  1. 在配置文件添加节点
"WeTools": {
    "Worker": {
      "name":"testworker",//可选,默认为特性输入的名称
      "workername":"",//可选,默认为特性解析的worker类名
      "Enable": true
    },
    "Worker2":{
     "Enable": true
    }
  }
 或者
 自定义配置节点
 "myconfig": {
    "DemoWorker": {
      "name": "adf123",
      "Enable": true
    }
  }
 或者
 根节点下直接添加
 "DemoWorker": {
    "Enable": true
  },
  "DemoWorker2": {
    "Enable": true
  },
  1. 新建worker,继承WeToolBackgroundService 并在worker类添加特性

     	[Worker("DemoWorker")]
        public class TestWorker : WeToolBackgroundService
        {
        }
    

3.在Program类 ConfigureServices 里注册服务

参数对应 1 中的配置 选择不同的方法。

这里不需要调用 AddServiceOptions 方法。

services.UseWorker(hostContext.Configuration);
services.UseWorker(hostContext);
services.UseWorker(hostContext.Configuration.GetSection("myconfig"));

现在即可启动程序。

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.2 389 6/7/2021
1.0.1 351 5/26/2021
1.0.0 329 5/21/2021