-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathBootstrap.cs
63 lines (53 loc) · 1.86 KB
/
Bootstrap.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
#region copyright
// Autofac Quartz integration
// https://github.com/alphacloud/Autofac.Extras.Quartz
// Licensed under MIT license.
// Copyright (c) 2014-2022 Alphacloud.Net
#endregion
// ReSharper disable once CheckNamespace
namespace SimpleService.Configuration;
using System.Collections.Specialized;
using AppServices;
using Autofac;
using Autofac.Extras.Quartz;
using Jobs;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;
class Bootstrap
{
public static void InitializeLogger()
{
var log = new LoggerConfiguration()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.CreateLogger();
Log.Logger = log;
}
internal static ContainerBuilder ConfigureContainer(ContainerBuilder cb)
{
// configure and register Quartz
var schedulerConfig = new NameValueCollection {
{ "quartz.threadPool.threadCount", "3" },
{ "quartz.scheduler.threadName", "Scheduler" }
};
cb.Register(_ => new ScopedDependency("global"))
.AsImplementedInterfaces()
.SingleInstance();
cb.RegisterModule(new QuartzAutofacFactoryModule {
ConfigurationProvider = _ => schedulerConfig,
JobScopeConfigurator = (builder, tag) => {
// override dependency for job scope
builder.Register(_ => new ScopedDependency("job-local " + DateTime.UtcNow.ToLongTimeString()))
.AsImplementedInterfaces()
.InstancePerMatchingLifetimeScope(tag);
}
});
cb.RegisterModule(new QuartzAutofacJobsModule(typeof(HeartbeatJob).Assembly));
RegisterComponents(cb);
return cb;
}
internal static void RegisterComponents(ContainerBuilder cb)
{
// register dependencies
cb.RegisterType<HeartbeatService>().As<IHeartbeatService>();
}
}