2021-09-07 05:15:45 +00:00
|
|
|
using System;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Autofac;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Nitride.Commands;
|
2022-06-05 18:44:51 +00:00
|
|
|
using Nitride.Temporal.Cli;
|
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Serilog;
|
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
using Expires = Nitride.Temporal.Cli.ExpiresPipelineCommandOption;
|
|
|
|
|
|
|
|
namespace Nitride.Temporal;
|
|
|
|
|
|
|
|
public static class NitrideTemporalBuilderExtensions
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Extends the builder to allow for configuring the temporal
|
|
|
|
/// settings for generation.
|
|
|
|
/// </summary>
|
2022-06-07 02:40:31 +00:00
|
|
|
public static NitrideBuilder UseTemporal(
|
|
|
|
this NitrideBuilder builder,
|
|
|
|
Action<NitrideTemporalConfiguration>? configure = null)
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
2022-06-07 02:40:31 +00:00
|
|
|
// Get the configuration so we can set the various options.
|
|
|
|
var config = new NitrideTemporalConfiguration();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
configure?.Invoke(config);
|
2022-06-07 02:03:02 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
// Add in the module registration.
|
|
|
|
builder.ConfigureContainer(
|
|
|
|
x =>
|
|
|
|
{
|
|
|
|
// Register the module.
|
|
|
|
x.RegisterModule<NitrideTemporalModule>();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
// Add in the CLI options.
|
|
|
|
if (config.AddDateOptionToCommandLine)
|
2022-06-05 18:44:51 +00:00
|
|
|
{
|
|
|
|
x.RegisterType<DatePipelineCommandOption>().As<IPipelineCommandOption>();
|
2022-06-07 02:40:31 +00:00
|
|
|
}
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
if (config.AddExpireOptionToCommandLine && config.Expiration != null)
|
|
|
|
{
|
|
|
|
x.Register(
|
|
|
|
context =>
|
|
|
|
{
|
|
|
|
ILogger logger = context.Resolve<ILogger>();
|
|
|
|
Timekeeper clock = context.Resolve<Timekeeper>();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
return new Expires(logger, clock, config.Expiration);
|
|
|
|
})
|
|
|
|
.As<IPipelineCommandOption>();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.ConfigureSite(
|
|
|
|
(_, scope) =>
|
2022-06-05 18:44:51 +00:00
|
|
|
{
|
2022-06-07 02:40:31 +00:00
|
|
|
Timekeeper timekeeper = scope.Resolve<Timekeeper>();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
timekeeper.DateTimeZone = timekeeper.DateTimeZone;
|
2022-06-05 18:44:51 +00:00
|
|
|
});
|
2022-06-07 02:40:31 +00:00
|
|
|
|
|
|
|
return builder;
|
2021-09-07 05:15:45 +00:00
|
|
|
}
|
|
|
|
}
|