Skip to content

Commit

Permalink
Also change directory during Hastlayer.Create().
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Oct 1, 2023
1 parent f9234c2 commit 2f2fb57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Hastlayer/Hast.Common/Services/DirectoryScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DirectoryScope : IDisposable
public DirectoryScope(string path)
{
_oldPath = Environment.CurrentDirectory;
Environment.CurrentDirectory = path;
Directory.SetCurrentDirectory(string.IsNullOrWhiteSpace(path) ? "." : path.Trim());
}

public void Dispose()
Expand All @@ -28,7 +28,7 @@ protected virtual void Dispose(bool disposing)
{
if (!_disposed && Directory.Exists(_oldPath))
{
Environment.CurrentDirectory = _oldPath;
Directory.SetCurrentDirectory(_oldPath);
}

_disposed = true;
Expand Down
6 changes: 5 additions & 1 deletion src/Hastlayer/Hast.Layer/Hastlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@ public static void ConfigureLogging(IServiceCollection services, Action<ILogging
/// </para>
/// </remarks>
/// <param name="configuration">Configuration for Hastlayer.</param>
/// <param name="inAssemblyDirectory">
/// If <see langword="true"/>, the executing assembly's directory is used instead of the current working directory.
/// </param>
/// <returns>A newly created <see cref="Hastlayer"/> instance.</returns>
public static Hastlayer Create(IHastlayerConfiguration configuration)
public static Hastlayer Create(IHastlayerConfiguration configuration, bool inAssemblyDirectory = true)
{
Argument.ThrowIfNull(configuration, nameof(configuration));
Argument.ThrowIfNull(configuration.Extensions, nameof(configuration.Extensions));

using var workingDirectory = new DirectoryScope(inAssemblyDirectory ? AppDataFolder.AssemblyDirectory : ".");
var hastlayer = new Hastlayer(configuration);
hastlayer.LoadHost();
return hastlayer;
Expand Down

0 comments on commit 2f2fb57

Please sign in to comment.