diff --git a/src/Framework/Framework/DependencyInjection/DotVVMServiceCollectionExtensions.cs b/src/Framework/Framework/DependencyInjection/DotVVMServiceCollectionExtensions.cs index fb1c4deff2..e5f5853053 100644 --- a/src/Framework/Framework/DependencyInjection/DotVVMServiceCollectionExtensions.cs +++ b/src/Framework/Framework/DependencyInjection/DotVVMServiceCollectionExtensions.cs @@ -62,6 +62,8 @@ public static IServiceCollection RegisterDotVVMServices(IServiceCollection servi services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs b/src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs index 0c25033cb8..c7b2f1be80 100644 --- a/src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs +++ b/src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs @@ -3,18 +3,20 @@ using System.Linq; using System.Text; using DotVVM.Framework.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; namespace DotVVM.Framework.Hosting { public class AggregateMarkupFileLoader : IMarkupFileLoader { - public List Loaders { get; private set; } = new List(); + private readonly List loaders; - public AggregateMarkupFileLoader() + public AggregateMarkupFileLoader(IOptions options, IServiceProvider serviceProvider) { - // the EmbeddedMarkupFileLoader must be registered before DefaultMarkupFileLoader (which gets wrapped by HotReloadMarkupFileLoader) - Loaders.Add(new EmbeddedMarkupFileLoader()); - Loaders.Add(new DefaultMarkupFileLoader()); + loaders = options.Value.LoaderTypes + .Select(p => (IMarkupFileLoader)serviceProvider.GetRequiredService(p)) + .ToList(); } /// @@ -22,9 +24,9 @@ public AggregateMarkupFileLoader() /// public MarkupFile? GetMarkup(DotvvmConfiguration configuration, string virtualPath) { - for (int i = 0; i < Loaders.Count; i++) + for (var i = 0; i < loaders.Count; i++) { - var result = Loaders[i].GetMarkup(configuration, virtualPath); + var result = loaders[i].GetMarkup(configuration, virtualPath); if (result != null) { return result; diff --git a/src/Framework/Framework/Hosting/AggregateMarkupFileLoaderOptions.cs b/src/Framework/Framework/Hosting/AggregateMarkupFileLoaderOptions.cs new file mode 100644 index 0000000000..31e9444d9f --- /dev/null +++ b/src/Framework/Framework/Hosting/AggregateMarkupFileLoaderOptions.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace DotVVM.Framework.Hosting; + +public class AggregateMarkupFileLoaderOptions +{ + public List LoaderTypes { get; } + + public AggregateMarkupFileLoaderOptions() + { + LoaderTypes = new() + { + // the EmbeddedMarkupFileLoader must be registered before DefaultMarkupFileLoader (which gets wrapped by HotReloadMarkupFileLoader) + typeof(EmbeddedMarkupFileLoader), + typeof(DefaultMarkupFileLoader) + }; + } +} diff --git a/src/Framework/Framework/Hosting/MarkupFile.cs b/src/Framework/Framework/Hosting/MarkupFile.cs index 8821a97fe9..8dc82c8d58 100644 --- a/src/Framework/Framework/Hosting/MarkupFile.cs +++ b/src/Framework/Framework/Hosting/MarkupFile.cs @@ -67,7 +67,7 @@ public MarkupFile(string fileName, string fullPath) }; } - internal MarkupFile(string fileName, string fullPath, string contents) + public MarkupFile(string fileName, string fullPath, string contents) { FileName = fileName; FullPath = fullPath; diff --git a/src/Tools/HotReload/AspNetCore/Configuration/DotvvmServiceCollectionExtensions.cs b/src/Tools/HotReload/AspNetCore/Configuration/DotvvmServiceCollectionExtensions.cs index eae9fc2968..49d77e53da 100644 --- a/src/Tools/HotReload/AspNetCore/Configuration/DotvvmServiceCollectionExtensions.cs +++ b/src/Tools/HotReload/AspNetCore/Configuration/DotvvmServiceCollectionExtensions.cs @@ -20,7 +20,17 @@ public static void AddHotReload(this IDotvvmServiceCollection services) services.Services.AddSignalR(); services.Services.AddSingleton(); - services.Services.AddSingleton(); + services.Services.Configure(options => + { + var index = options.LoaderTypes.FindIndex(l => l == typeof(DefaultMarkupFileLoader)); + if (index < 0) + { + throw new InvalidOperationException("DotVVM Hot reload could not be initialized - the DefaultMarkupLoader was not found in the AggregateMarkupFileLoader Loaders collection."); + } + + options.LoaderTypes[index] = typeof(HotReloadMarkupFileLoader); + }); + services.Services.AddSingleton(); services.Services.Configure(RegisterResources); services.Services.AddTransient(provider => diff --git a/src/Tools/HotReload/Common/HotReloadAggregateMarkupFileLoader.cs b/src/Tools/HotReload/Common/HotReloadAggregateMarkupFileLoader.cs deleted file mode 100644 index 968b88cde8..0000000000 --- a/src/Tools/HotReload/Common/HotReloadAggregateMarkupFileLoader.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using DotVVM.Framework.Configuration; -using DotVVM.Framework.Hosting; - -namespace DotVVM.HotReload -{ - public class HotReloadAggregateMarkupFileLoader : AggregateMarkupFileLoader - { - - public HotReloadAggregateMarkupFileLoader(IMarkupFileChangeNotifier notifier, DotvvmConfiguration configuration) - { - var index = Loaders.FindIndex(l => l is DefaultMarkupFileLoader); - if (index < 0) - { - throw new InvalidOperationException("DotVVM Hot reload could not be initialized - the DefaultMarkupLoader was not found in the AggregateMarkupFileLoader Loaders collection."); - } - var defaultLoader = (DefaultMarkupFileLoader)Loaders[index]; - Loaders[index] = new HotReloadMarkupFileLoader(defaultLoader, notifier, configuration); - } - - } -} diff --git a/src/Tools/HotReload/Owin/Configuration/DotvvmServiceCollectionExtensions.cs b/src/Tools/HotReload/Owin/Configuration/DotvvmServiceCollectionExtensions.cs index 1fe53a139f..b6942ec7ca 100644 --- a/src/Tools/HotReload/Owin/Configuration/DotvvmServiceCollectionExtensions.cs +++ b/src/Tools/HotReload/Owin/Configuration/DotvvmServiceCollectionExtensions.cs @@ -19,7 +19,16 @@ public static class DotvvmServiceCollectionExtensions public static void AddHotReload(this IDotvvmServiceCollection services, DotvvmHotReloadOptions? options = null) { services.Services.AddSingleton(); - services.Services.AddSingleton(); + services.Services.Configure(options => { + var index = options.LoaderTypes.FindIndex(l => l == typeof(DefaultMarkupFileLoader)); + if (index < 0) + { + throw new InvalidOperationException("DotVVM Hot reload could not be initialized - the DefaultMarkupLoader was not found in the AggregateMarkupFileLoader Loaders collection."); + } + + options.LoaderTypes[index] = typeof(HotReloadMarkupFileLoader); + }); + services.Services.AddSingleton(); services.Services.Configure(config => RegisterResources(config, options ?? new DotvvmHotReloadOptions())); services.Services.AddTransient(provider =>