Skip to content

Commit

Permalink
If we don't want hot reloading but want load assemblies into memory t…
Browse files Browse the repository at this point in the history
…o keep files lockfree in order to able to reload manually in future.
  • Loading branch information
bergi9 committed Mar 31, 2020
1 parent 6f98de6 commit 7891b09
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Plugins/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,27 @@ public bool IsUnloadable
set => _isUnloadable = value;
}

private bool _loadInMemory;

/// <summary>
/// Loads assemblies into memory in order to not lock files.
/// As example use case here would be: no hot reloading but able to
/// replace files and reload manually at later time
/// </summary>
public bool LoadInMemory
{
get => _loadInMemory || EnableHotReload;
set => _loadInMemory = value;
}

/// <summary>
/// When any of the loaded files changes on disk, the plugin will be reloaded.
/// Use the event <see cref="PluginLoader.Reloaded" /> to be notified of changes.
/// </summary>
/// <remarks>
/// It will load assemblies into memory in order to not lock files
/// <see cref="LoadInMemory"/>
/// </remarks>
public bool EnableHotReload { get; set; }

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ private static AssemblyLoadContextBuilder CreateLoadContextBuilder(PluginConfig
{
builder.EnableUnloading();
}

if (config.EnableHotReload)
if (config.LoadInMemory)
{
builder.PreloadAssembliesIntoMemory();
builder.ShadowCopyNativeLibraries();
Expand Down
2 changes: 2 additions & 0 deletions src/Plugins/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
McMaster.NETCore.Plugins.PluginConfig.LoadInMemory.get -> bool
McMaster.NETCore.Plugins.PluginConfig.LoadInMemory.set -> void

0 comments on commit 7891b09

Please sign in to comment.