fix: prevent the Use*() from being used twice
This commit is contained in:
parent
636c85c021
commit
0cddef9e96
|
@ -6,8 +6,20 @@ namespace MfGames.Nitride.Calendar;
|
|||
|
||||
public static class NitrideCalendarBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseCalendar(this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseCalendar() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder
|
||||
.ConfigureContainer(x => x.RegisterModule<NitrideCalendarModule>());
|
||||
}
|
||||
|
|
|
@ -2,8 +2,20 @@ namespace MfGames.Nitride.Exec.Setup;
|
|||
|
||||
public static class NitrideExecBuilderExtensions
|
||||
{
|
||||
public static NitrideBuilder UseFeeds(this NitrideBuilder builder)
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseExec(this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseExec() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder
|
||||
.UseModule<NitrideExecModule>();
|
||||
}
|
||||
|
|
|
@ -6,9 +6,21 @@ namespace MfGames.Nitride.Feeds;
|
|||
|
||||
public static class NitrideFeedsBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseFeeds(this NitrideBuilder builder)
|
||||
{
|
||||
return builder.UseTemporal()
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseFeeds() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder
|
||||
.ConfigureContainer(x => x.RegisterModule<NitrideFeedsModule>());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using Autofac;
|
||||
|
||||
using MfGames.Nitride.Temporal.Setup;
|
||||
|
||||
namespace MfGames.Nitride.Feeds;
|
||||
|
||||
public class NitrideFeedsModule : Module
|
||||
|
@ -7,6 +9,7 @@ public class NitrideFeedsModule : Module
|
|||
/// <inheritdoc />
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterModule<NitrideTemporalModule>();
|
||||
builder.RegisterOperators(this);
|
||||
builder.RegisterValidators(this);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,20 @@ namespace MfGames.Nitride.Gemtext;
|
|||
|
||||
public static class NitrideGemtextBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseGemtext(this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseGemtext() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder.ConfigureContainer(
|
||||
x => x.RegisterModule<NitrideGemtextModule>());
|
||||
}
|
||||
|
|
|
@ -6,8 +6,20 @@ namespace MfGames.Nitride.Handlebars;
|
|||
|
||||
public static class NitrideHandlebarsBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseHandlebars(this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseHandlebars() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder
|
||||
.ConfigureContainer(
|
||||
x => x.RegisterModule<NitrideHandlebarsModule>());
|
||||
|
|
|
@ -4,8 +4,20 @@ namespace MfGames.Nitride.Html;
|
|||
|
||||
public static class NitrideHtmlBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseHtml(this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseHtml() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder.ConfigureContainer(
|
||||
x => x.RegisterModule<NitrideHtmlModule>());
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace MfGames.Nitride.IO.Setup;
|
|||
/// </summary>
|
||||
public static class NitrideIOBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseIO(
|
||||
this NitrideBuilder builder,
|
||||
DirectoryInfo rootDirectory)
|
||||
|
@ -22,6 +24,15 @@ public static class NitrideIOBuilderExtensions
|
|||
this NitrideBuilder builder,
|
||||
Action<NitrideIOConfiguration>? configure = null)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseIO() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
var config = new NitrideIOConfiguration();
|
||||
|
||||
|
|
|
@ -4,8 +4,20 @@ namespace MfGames.Nitride.Json;
|
|||
|
||||
public static class NitrideJsonBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseJson(this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseJson() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder.ConfigureContainer(
|
||||
x => x.RegisterModule<NitrideJsonModule>());
|
||||
}
|
||||
|
|
|
@ -4,8 +4,20 @@ namespace MfGames.Nitride.Markdown;
|
|||
|
||||
public static class NitrideMarkdownBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseMarkdown(this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseMarkdown() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder.ConfigureContainer(
|
||||
x => x.RegisterModule<NitrideMarkdownModule>());
|
||||
}
|
||||
|
|
|
@ -4,10 +4,22 @@ namespace MfGames.Nitride.Slugs;
|
|||
|
||||
public static class NitrideSlugsBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseSlugs(
|
||||
this NitrideBuilder builder,
|
||||
ISlugConverter slugs)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseSlugs() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
if (slugs == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(slugs));
|
||||
|
|
|
@ -4,6 +4,8 @@ namespace MfGames.Nitride.Temporal.Schedules.Setup;
|
|||
|
||||
public static class NitrideTemporalSchedulesBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
/// <summary>
|
||||
/// Extends the builder to allow for configuring the temporal
|
||||
/// schedules during processing.
|
||||
|
@ -11,6 +13,16 @@ public static class NitrideTemporalSchedulesBuilderExtensions
|
|||
public static NitrideBuilder UseTemporalSchedules(
|
||||
this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseTemporalSchedules() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder.ConfigureContainer(
|
||||
x => x.RegisterModule<NitrideTemporalSchedulesModule>());
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public static class NitrideTemporalBuilderExtensions
|
|||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseTemporal more than once.");
|
||||
"Cannot use UseTemporal() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
|
|
@ -4,8 +4,20 @@ namespace MfGames.Nitride.Yaml;
|
|||
|
||||
public static class NitrideYamlBuilderExtensions
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
public static NitrideBuilder UseYaml(this NitrideBuilder builder)
|
||||
{
|
||||
// If we've already loaded, then we have a problem.
|
||||
if (loaded)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot use UseYaml() more than once.");
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
// Get the configuration so we can set the various options.
|
||||
return builder.ConfigureContainer(
|
||||
x => x.RegisterModule<NitrideYamlModule>());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue