Skip to content

Commit

Permalink
Remove action delegates for configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Nov 5, 2024
1 parent c45a597 commit 9039920
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,24 @@ namespace Microsoft.Extensions.DependencyInjection;

public static class IMachineBuilderExtensions
{
public static IMachineBuilder AddServiceOptions(
this IMachineBuilder builder,
Action<ServiceOptions> configureOptions
)
{
builder.Services.Configure(configureOptions);
return builder;
}

public static IMachineBuilder AddServiceOptions(this IMachineBuilder builder, IConfiguration config)
{
builder.Services.Configure<ServiceOptions>(config);
return builder;
}

public static IMachineBuilder AddSmtTransferEngineOptions(
this IMachineBuilder builder,
Action<SmtTransferEngineOptions> configureOptions
)
{
builder.Services.Configure(configureOptions);
return builder;
}

public static IMachineBuilder AddSmtTransferEngineOptions(this IMachineBuilder builder, IConfiguration config)
{
builder.Services.Configure<SmtTransferEngineOptions>(config);
return builder;
}

public static IMachineBuilder AddClearMLOptions(
this IMachineBuilder builder,
Action<ClearMLOptions> configureOptions
)
{
builder.Services.Configure(configureOptions);
return builder;
}

public static IMachineBuilder AddClearMLOptions(this IMachineBuilder builder, IConfiguration config)
{
builder.Services.Configure<ClearMLOptions>(config);
return builder;
}

public static IMachineBuilder AddDistributedReaderWriterLockOptions(
this IMachineBuilder build,
Action<DistributedReaderWriterLockOptions> configureOptions
)
{
build.Services.Configure(configureOptions);
return build;
}

public static IMachineBuilder AddDistributedReaderWriterLockOptions(
this IMachineBuilder build,
IConfiguration config
Expand All @@ -68,45 +32,18 @@ IConfiguration config
return build;
}

public static IMachineBuilder AddMessageOutboxOptions(
this IMachineBuilder builder,
Action<MessageOutboxOptions> configureOptions
)
{
builder.Services.Configure(configureOptions);
return builder;
}

public static IMachineBuilder AddMessageOutboxOptions(this IMachineBuilder builder, IConfiguration config)
{
builder.Services.Configure<MessageOutboxOptions>(config);
return builder;
}

public static IMachineBuilder AddSharedFileOptions(
this IMachineBuilder builder,
Action<SharedFileOptions> configureOptions
)
{
builder.Services.Configure(configureOptions);
return builder;
}

public static IMachineBuilder AddSharedFileOptions(this IMachineBuilder builder, IConfiguration config)
{
builder.Services.Configure<SharedFileOptions>(config);
return builder;
}

public static IMachineBuilder AddBuildJobOptions(
this IMachineBuilder builder,
Action<BuildJobOptions> configureOptions
)
{
builder.Services.Configure(configureOptions);
return builder;
}

public static IMachineBuilder AddBuildJobOptions(this IMachineBuilder builder, IConfiguration config)
{
builder.Services.Configure<BuildJobOptions>(config);
Expand All @@ -116,21 +53,11 @@ public static IMachineBuilder AddBuildJobOptions(this IMachineBuilder builder, I
public static IMachineBuilder AddThotSmtModel(this IMachineBuilder builder)
{
if (builder.Configuration is null)
return builder.AddThotSmtModel(o => { });
throw new InvalidOperationException("Configuration is required");
else
return builder.AddThotSmtModel(builder.Configuration.GetSection(ThotSmtModelOptions.Key));
}

public static IMachineBuilder AddThotSmtModel(
this IMachineBuilder builder,
Action<ThotSmtModelOptions> configureOptions
)
{
builder.Services.Configure(configureOptions);
builder.Services.AddSingleton<ISmtModelFactory, ThotSmtModelFactory>();
return builder;
}

public static IMachineBuilder AddThotSmtModel(this IMachineBuilder builder, IConfiguration config)
{
builder.Services.Configure<ThotSmtModelOptions>(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ public static IMachineBuilder AddMachine(this IServiceCollection services, IConf
var builder = new MachineBuilder(services, configuration);
if (configuration is null)
{
builder.AddServiceOptions(o => { });
builder.AddSharedFileOptions(o => { });
builder.AddSmtTransferEngineOptions(o => { });
builder.AddClearMLOptions(o => { });
builder.AddDistributedReaderWriterLockOptions(o => { });
builder.AddBuildJobOptions(o => { });
builder.AddMessageOutboxOptions(o => { });
throw new InvalidOperationException("Configuration is required");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ namespace Microsoft.Extensions.DependencyInjection;

public static class IServalBuilderExtensions
{
public static IServalBuilder AddAssessment(this IServalBuilder builder, Action<AssessmentOptions>? configure = null)
public static IServalBuilder AddAssessment(this IServalBuilder builder)
{
if (builder.Configuration is null)
{
builder.AddApiOptions(o => { });
builder.AddDataFileOptions(o => { });
throw new InvalidOperationException("Configuration is required");
}
else
{
Expand All @@ -24,8 +23,6 @@ public static IServalBuilder AddAssessment(this IServalBuilder builder, Action<A

var assessmentOptions = new AssessmentOptions();
builder.Configuration?.GetSection(AssessmentOptions.Key).Bind(assessmentOptions);
if (configure is not null)
configure(assessmentOptions);

foreach (EngineInfo engine in assessmentOptions.Engines)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public static class IServalBuilderExtensions
public static IServalBuilder AddDataFiles(this IServalBuilder builder)
{
if (builder.Configuration is null)
builder.AddDataFileOptions(o => { });
throw new InvalidOperationException("Configuration is required");
else
builder.AddDataFileOptions(builder.Configuration.GetSection(DataFileOptions.Key));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,12 @@

public static class IServalBuilderExtensions
{
public static IServalBuilder AddDataFileOptions(
this IServalBuilder builder,
Action<DataFileOptions> configureOptions
)
{
builder.Services.Configure(configureOptions);
return builder;
}

public static IServalBuilder AddDataFileOptions(this IServalBuilder builder, IConfiguration config)
{
builder.Services.Configure<DataFileOptions>(config);
return builder;
}

public static IServalBuilder AddApiOptions(this IServalBuilder builder, Action<ApiOptions> configureOptions)
{
builder.Services.Configure(configureOptions);
return builder;
}

public static IServalBuilder AddApiOptions(this IServalBuilder builder, IConfiguration config)
{
builder.Services.Configure<ApiOptions>(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ namespace Microsoft.Extensions.DependencyInjection;

public static class IServalBuilderExtensions
{
public static IServalBuilder AddTranslation(
this IServalBuilder builder,
Action<TranslationOptions>? configure = null
)
public static IServalBuilder AddTranslation(this IServalBuilder builder)
{
if (builder.Configuration is null)
{
builder.AddApiOptions(o => { });
builder.AddDataFileOptions(o => { });
throw new InvalidOperationException("Configuration is required");
}
else
{
Expand All @@ -27,8 +23,6 @@ public static IServalBuilder AddTranslation(

var translationOptions = new TranslationOptions();
builder.Configuration?.GetSection(TranslationOptions.Key).Bind(translationOptions);
if (configure is not null)
configure(translationOptions);

foreach (EngineInfo engine in translationOptions.Engines)
{
Expand Down

0 comments on commit 9039920

Please sign in to comment.