Skip to content

Commit

Permalink
Refactor: Pull out XllPath into settable property
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspermarstal committed Oct 26, 2024
1 parent e6741df commit e9702d5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Cellm/Services/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Cellm.Services;
internal static class ServiceLocator
{
private static readonly Lazy<IServiceProvider> _serviceProvider = new(() => ConfigureServices(new ServiceCollection()).BuildServiceProvider());

internal static string? ConfigurationPath { get; set; } = ExcelDnaUtil.XllPathInfo?.Directory?.FullName;
public static IServiceProvider ServiceProvider => _serviceProvider.Value;

public static T Get<T>() where T : notnull
Expand All @@ -32,12 +32,14 @@ public static T Get<T>() where T : notnull

private static IServiceCollection ConfigureServices(IServiceCollection services)
{
// Configurations
var XllPath = ExcelDnaUtil.XllPathInfo?.Directory?.FullName ??
throw new CellmException($"Unable to configure app, invalid value for ExcelDnaUtil.XllPathInfo='{ExcelDnaUtil.XllPathInfo}'");
if (string.IsNullOrEmpty(ConfigurationPath))
{
throw new CellmException($"Unable to configure app, invalid value for ExcelDnaUtil.XllPathInfo='{ConfigurationPath}'");
}

// Configurations
IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(XllPath)
.SetBasePath(ConfigurationPath)
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.Local.json", true)
.Build();
Expand Down

0 comments on commit e9702d5

Please sign in to comment.