-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSingleTaskServiceHandler.cs
More file actions
51 lines (46 loc) · 2.3 KB
/
SingleTaskServiceHandler.cs
File metadata and controls
51 lines (46 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Simplify.System;
namespace Simplify.WindowsServices;
/// <summary>
/// Provides class which runs as a windows service and periodically creates a class instance of specified type and launches it in separated thread
/// </summary>
/// <typeparam name="T"></typeparam>
public class SingleTaskServiceHandler<T> : MultitaskServiceHandler
where T : class
{
/// <summary>
/// Initializes a new instance of the <see cref="SingleTaskServiceHandler{T}" /> class.
/// </summary>
/// <param name="automaticallyRegisterUserType">if set to <c>true</c> then user type T will be registered in DIContainer with transient lifetime.</param>
/// <param name="configurationSectionName">Name of the configuration section.</param>
/// <param name="invokeMethodName">Name of the invoke method.</param>
/// <param name="startupArgs">The startup arguments.</param>
public SingleTaskServiceHandler(bool automaticallyRegisterUserType = false,
string configurationSectionName = "ServiceSettings",
string invokeMethodName = "Run",
object? startupArgs = null)
{
var assemblyInfo = new AssemblyInfo(Assembly.GetCallingAssembly());
ServiceName = assemblyInfo.Title;
AddJob<T>(configurationSectionName, invokeMethodName, automaticallyRegisterUserType, startupArgs);
}
/// <summary>
/// Initializes a new instance of the <see cref="SingleTaskServiceHandler{T}" /> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="automaticallyRegisterUserType">if set to <c>true</c> then user type T will be registered in DIContainer with transient lifetime.</param>
/// <param name="configurationSectionName">Name of the configuration section.</param>
/// <param name="invokeMethodName">Name of the invoke method.</param>
/// <param name="startupArgs">The startup arguments.</param>
public SingleTaskServiceHandler(IConfiguration configuration,
bool automaticallyRegisterUserType = false,
string configurationSectionName = "ServiceSettings",
string invokeMethodName = "Run",
object? startupArgs = null)
{
var assemblyInfo = new AssemblyInfo(Assembly.GetCallingAssembly());
ServiceName = assemblyInfo.Title;
AddJob<T>(configuration, configurationSectionName, invokeMethodName, automaticallyRegisterUserType, startupArgs);
}
}