Skip to content

Commit fced7b6

Browse files
committed
Add Create and CreateLite helpers
1 parent 7805397 commit fced7b6

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

src/HotAvalonia.Extensions/AvaloniaHotReloadExtensions.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ private static void EnableHotReload(Application app, AvaloniaProjectLocator proj
101101
{
102102
if (!s_apps.TryGetValue(app, out IHotReloadContext? context))
103103
{
104-
IHotReloadContext appDomainContext = AvaloniaHotReloadContext.FromAppDomain();
105-
IHotReloadContext assetContext = AvaloniaHotReloadContext.ForAssets();
106-
context = HotReloadContext.Combine(appDomainContext, assetContext);
104+
#if ENABLE_LITE_XAML_HOT_RELOAD
105+
context = AvaloniaHotReloadContext.CreateLite(projectLocator);
106+
#else
107+
context = AvaloniaHotReloadContext.Create(projectLocator);
108+
#endif
107109
s_apps.Add(app, context);
108110
}
109111

src/HotAvalonia.Extensions/AvaloniaHotReloadExtensions.fs

+5-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ type internal AvaloniaHotReloadExtensions =
9595
match s_apps.TryGetValue(app) with
9696
| true, context -> context.EnableHotReload()
9797
| _ ->
98-
let appDomainContext = AvaloniaHotReloadContext.FromAppDomain()
99-
let assetContext = AvaloniaHotReloadContext.ForAssets()
100-
let context = HotReloadContext.Combine(appDomainContext, assetContext)
98+
#if ENABLE_LITE_XAML_HOT_RELOAD
99+
let context = AvaloniaHotReloadContext.CreateLite(projectLocator)
100+
#else
101+
let context = AvaloniaHotReloadContext.Create(projectLocator)
102+
#endif
101103
s_apps.Add(app, context)
102104

103105
context.EnableHotReload()

src/HotAvalonia.Extensions/AvaloniaHotReloadExtensions.vb

+5-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ Namespace Global.HotAvalonia
9292
Private Sub EnableHotReload(ByVal app As Application, ByVal projectLocator As AvaloniaProjectLocator)
9393
Dim context As IHotReloadContext = Nothing
9494
If Not s_apps.TryGetValue(app, context) Then
95-
Dim appDomainContext As IHotReloadContext = AvaloniaHotReloadContext.FromAppDomain()
96-
Dim assetContext As IHotReloadContext = AvaloniaHotReloadContext.ForAssets()
97-
context = HotReloadContext.Combine(appDomainContext, assetContext)
95+
#If ENABLE_LITE_XAML_HOT_RELOAD Then
96+
context = AvaloniaHotReloadContext.CreateLite(projectLocator)
97+
#Else
98+
context = AvaloniaHotReloadContext.Create(projectLocator)
99+
#End If
98100
s_apps.Add(app, context)
99101
End If
100102

src/HotAvalonia/AvaloniaHotReloadContext.cs

+46
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.ComponentModel;
12
using System.Reflection;
23
using Avalonia.Controls;
34
using Avalonia.Markup.Xaml.Converters;
@@ -15,6 +16,51 @@ namespace HotAvalonia;
1516
/// </summary>
1617
public static class AvaloniaHotReloadContext
1718
{
19+
/// <inheritdoc cref="Create(AvaloniaProjectLocator)"/>
20+
[EditorBrowsable(EditorBrowsableState.Never)]
21+
public static IHotReloadContext Create()
22+
=> Create(new AvaloniaProjectLocator());
23+
24+
/// <summary>
25+
/// Creates a hot reload context for the current environment.
26+
/// </summary>
27+
/// <remarks>
28+
/// This method is opinionated and represents the "best" way to create
29+
/// a hot reload context for the current environment.
30+
/// However, the specific details of what constitutes "best" are subject to change.
31+
/// </remarks>
32+
/// <param name="projectLocator">The project locator used to find source directories of assemblies.</param>
33+
/// <returns>A hot reload context for the current environment.</returns>
34+
[EditorBrowsable(EditorBrowsableState.Never)]
35+
public static IHotReloadContext Create(AvaloniaProjectLocator projectLocator)
36+
{
37+
IHotReloadContext appDomainContext = FromAppDomain(AppDomain.CurrentDomain, projectLocator);
38+
IHotReloadContext assetContext = ForAssets(AvaloniaServiceProvider.Current, projectLocator);
39+
return HotReloadContext.Combine([appDomainContext, assetContext]);
40+
}
41+
42+
/// <inheritdoc cref="CreateLite(AvaloniaProjectLocator)"/>
43+
[EditorBrowsable(EditorBrowsableState.Never)]
44+
public static IHotReloadContext CreateLite()
45+
=> CreateLite(new AvaloniaProjectLocator());
46+
47+
/// <summary>
48+
/// Creates a lightweight hot reload context for the current environment.
49+
/// </summary>
50+
/// <remarks>
51+
/// This method is opinionated and represents the "best" lightweight way to create
52+
/// a hot reload context for the current environment. However, the specific details
53+
/// of what constitutes "best" are subject to change.
54+
/// </remarks>
55+
/// <param name="projectLocator">The project locator used to find source directories of assemblies.</param>
56+
/// <returns>A lightweight hot reload context for the current environment.</returns>
57+
[EditorBrowsable(EditorBrowsableState.Never)]
58+
public static IHotReloadContext CreateLite(AvaloniaProjectLocator projectLocator)
59+
{
60+
IHotReloadContext appDomainContext = FromAppDomain(AppDomain.CurrentDomain, projectLocator);
61+
return appDomainContext;
62+
}
63+
1864
/// <inheritdoc cref="ForAssets(IServiceProvider)"/>
1965
public static IHotReloadContext ForAssets()
2066
=> ForAssets(AvaloniaServiceProvider.Current);

0 commit comments

Comments
 (0)