Skip to content

Commit

Permalink
configuration not able to be null
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Nov 5, 2024
1 parent 9039920 commit 5e61336
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public interface IMachineBuilder
{
IServiceCollection Services { get; }
IConfiguration? Configuration { get; }
IConfiguration Configuration { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public static IMachineBuilder AddBuildJobOptions(this IMachineBuilder builder, I

public static IMachineBuilder AddThotSmtModel(this IMachineBuilder builder)
{
if (builder.Configuration is null)
throw new InvalidOperationException("Configuration is required");
else
return builder.AddThotSmtModel(builder.Configuration.GetSection(ThotSmtModelOptions.Key));
return builder.AddThotSmtModel(builder.Configuration.GetSection(ThotSmtModelOptions.Key));
}

public static IMachineBuilder AddThotSmtModel(this IMachineBuilder builder, IConfiguration config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static class IServiceCollectionExtensions
{
public static IMachineBuilder AddMachine(this IServiceCollection services, IConfiguration? configuration = null)
public static IMachineBuilder AddMachine(this IServiceCollection services, IConfiguration configuration)
{
if (!Sldr.IsInitialized)
Sldr.Initialize();
Expand All @@ -22,22 +22,13 @@ public static IMachineBuilder AddMachine(this IServiceCollection services, IConf
);

var builder = new MachineBuilder(services, configuration);
if (configuration is null)
{
throw new InvalidOperationException("Configuration is required");
}
else
{
builder.AddServiceOptions(configuration.GetSection(ServiceOptions.Key));
builder.AddSharedFileOptions(configuration.GetSection(SharedFileOptions.Key));
builder.AddSmtTransferEngineOptions(configuration.GetSection(SmtTransferEngineOptions.Key));
builder.AddClearMLOptions(configuration.GetSection(ClearMLOptions.Key));
builder.AddDistributedReaderWriterLockOptions(
configuration.GetSection(DistributedReaderWriterLockOptions.Key)
);
builder.AddBuildJobOptions(configuration.GetSection(BuildJobOptions.Key));
builder.AddMessageOutboxOptions(configuration.GetSection(MessageOutboxOptions.Key));
}
builder.AddServiceOptions(configuration.GetSection(ServiceOptions.Key));
builder.AddSharedFileOptions(configuration.GetSection(SharedFileOptions.Key));
builder.AddSmtTransferEngineOptions(configuration.GetSection(SmtTransferEngineOptions.Key));
builder.AddClearMLOptions(configuration.GetSection(ClearMLOptions.Key));
builder.AddDistributedReaderWriterLockOptions(configuration.GetSection(DistributedReaderWriterLockOptions.Key));
builder.AddBuildJobOptions(configuration.GetSection(BuildJobOptions.Key));
builder.AddMessageOutboxOptions(configuration.GetSection(MessageOutboxOptions.Key));
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Microsoft.Extensions.DependencyInjection;

internal class MachineBuilder(IServiceCollection services, IConfiguration? configuration) : IMachineBuilder
internal class MachineBuilder(IServiceCollection services, IConfiguration configuration) : IMachineBuilder
{
public IServiceCollection Services { get; } = services;
public IConfiguration? Configuration { get; } = configuration;
public IConfiguration Configuration { get; } = configuration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ public static class IServalBuilderExtensions
{
public static IServalBuilder AddAssessment(this IServalBuilder builder)
{
if (builder.Configuration is null)
{
throw new InvalidOperationException("Configuration is required");
}
else
{
builder.AddApiOptions(builder.Configuration.GetSection(ApiOptions.Key));
builder.AddDataFileOptions(builder.Configuration.GetSection(DataFileOptions.Key));
}
builder.AddApiOptions(builder.Configuration.GetSection(ApiOptions.Key));
builder.AddDataFileOptions(builder.Configuration.GetSection(DataFileOptions.Key));

builder.Services.AddScoped<IJobService, JobService>();
builder.Services.AddScoped<IResultService, ResultService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ public static class IServalBuilderExtensions
{
public static IServalBuilder AddDataFiles(this IServalBuilder builder)
{
if (builder.Configuration is null)
throw new InvalidOperationException("Configuration is required");
else
builder.AddDataFileOptions(builder.Configuration.GetSection(DataFileOptions.Key));
builder.AddDataFileOptions(builder.Configuration.GetSection(DataFileOptions.Key));

builder.Services.AddScoped<IDataFileService, DataFileService>();
builder.Services.AddHostedService<DeletedFileCleaner>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public interface IServalBuilder
{
IServiceCollection Services { get; }
IConfiguration? Configuration { get; }
IConfiguration Configuration { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static class IServiceCollectionExtensions
{
public static IServalBuilder AddServal(this IServiceCollection services, IConfiguration? configuration = null)
public static IServalBuilder AddServal(this IServiceCollection services, IConfiguration configuration)
{
services.AddTransient<IFileSystem, FileSystem>();
services.AddTransient<IScriptureDataFileService, ScriptureDataFileService>();
Expand Down
4 changes: 2 additions & 2 deletions src/Serval/src/Serval.Shared/Configuration/ServalBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Microsoft.Extensions.DependencyInjection;

internal class ServalBuilder(IServiceCollection services, IConfiguration? configuration) : IServalBuilder
internal class ServalBuilder(IServiceCollection services, IConfiguration configuration) : IServalBuilder
{
public IServiceCollection Services { get; } = services;
public IConfiguration? Configuration { get; } = configuration;
public IConfiguration Configuration { get; } = configuration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ public static class IServalBuilderExtensions
{
public static IServalBuilder AddTranslation(this IServalBuilder builder)
{
if (builder.Configuration is null)
{
throw new InvalidOperationException("Configuration is required");
}
else
{
builder.AddApiOptions(builder.Configuration.GetSection(ApiOptions.Key));
builder.AddDataFileOptions(builder.Configuration.GetSection(DataFileOptions.Key));
}
builder.AddApiOptions(builder.Configuration.GetSection(ApiOptions.Key));
builder.AddDataFileOptions(builder.Configuration.GetSection(DataFileOptions.Key));

builder.Services.AddScoped<IBuildService, BuildService>();
builder.Services.AddScoped<IPretranslationService, PretranslationService>();
Expand Down

0 comments on commit 5e61336

Please sign in to comment.