using System; using Autofac; using MfGames.Nitride.Commands; using MfGames.Nitride.Temporal.Cli; using Serilog; namespace MfGames.Nitride.Temporal.Setup; public static class NitrideTemporalBuilderExtensions { /// /// Extends the builder to allow for configuring the temporal /// settings for generation. /// public static NitrideBuilder UseTemporal( this NitrideBuilder builder, Action? configure = null) { // Get the configuration so we can set the various options. var config = new NitrideTemporalConfiguration(); configure?.Invoke(config); // Add in the module registration. builder.ConfigureContainer( x => { // Register the module. x.RegisterModule(); // Add in the CLI options. if (config.AddDateOptionToCommandLine) { x.RegisterType() .As(); } if (config.AddExpireOptionToCommandLine && config.Expiration != null) { x.Register( context => { ILogger logger = context.Resolve(); TimeService clock = context.Resolve(); return new ExpiresPipelineCommandOption( logger, clock, config.Expiration); }) .As(); } }); if (config.DateTimeZone != null) { builder.ConfigureSite( ( _, scope) => { ILogger logger = scope.Resolve(); TimeService timeService = scope.Resolve(); timeService.DateTimeZone = config.DateTimeZone; logger.Verbose( "Setting time zone to {Zone:l}", timeService.DateTimeZone); }); } return builder; } }