From 9bf4e0c412f924b0e2d6e798bbe2becde6d12ade Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 19 Jul 2018 13:37:45 +0300 Subject: [PATCH] Refactor bundling --- .../UI/Bundling/BundleConfigurationCollection.cs | 8 ++++++-- .../Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs | 10 ---------- .../AspNetCore/Mvc/UI/Bundling/IBundleManager.cs | 7 ------- .../TagHelpers/AbpTagHelperResourceService.cs | 9 ++++++--- .../TagHelpers/AbpTagHelperScriptService.cs | 13 ++++++++----- .../Bundling/TagHelpers/AbpTagHelperStyleService.cs | 9 ++++++--- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs index 9e16466fa4..ad71caec1d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs @@ -23,7 +23,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling /// Bundle name. /// Initial configuration action. /// Returns this object for chained calls. - public BundleConfigurationCollection Add([NotNull] string bundleName, [CanBeNull] Action configureAction = null) + public BundleConfigurationCollection Add( + [NotNull] string bundleName, + [CanBeNull] Action configureAction = null) { if (!TryAdd(bundleName, configureAction)) { @@ -41,7 +43,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling /// Bundle name. /// Initial configuration action. /// Returns true if added. Returns false if it's already added before. - public bool TryAdd([NotNull] string bundleName, [CanBeNull] Action configureAction = null) + public bool TryAdd( + [NotNull] string bundleName, + [CanBeNull] Action configureAction = null) { Check.NotNull(bundleName, nameof(bundleName)); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs index babd6441f6..000b38b8ea 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs @@ -142,16 +142,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling ); } - public virtual void CreateStyleBundle(string bundleName, Action configureAction) - { - Options.StyleBundles.TryAdd(bundleName, configureAction); - } - - public virtual void CreateScriptBundle(string bundleName, Action configureAction) - { - Options.ScriptBundles.TryAdd(bundleName, configureAction); - } - protected virtual bool IsBundlingEnabled() { switch (Options.Mode) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs index eb02eb27c9..39b092a00a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs @@ -1,18 +1,11 @@ -using System; using System.Collections.Generic; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { - //TODO: Bundle system needs refactoring/redesign - public interface IBundleManager { IReadOnlyList GetStyleBundleFiles(string bundleName); IReadOnlyList GetScriptBundleFiles(string bundleName); - - void CreateStyleBundle(string bundleName, Action configureAction); - - void CreateScriptBundle(string bundleName, Action configureAction); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs index 018f7c448e..5a22774a0f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.DependencyInjection; @@ -16,15 +17,17 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers public ILogger Logger { get; set; } protected IBundleManager BundleManager { get; } - protected IHybridWebRootFileProvider WebRootFileProvider { get; } - + protected readonly BundlingOptions Options; + protected AbpTagHelperResourceService( IBundleManager bundleManager, - IHybridWebRootFileProvider webRootFileProvider) + IHybridWebRootFileProvider webRootFileProvider, + IOptions options) { BundleManager = bundleManager; WebRootFileProvider = webRootFileProvider; + Options = options.Value; Logger = NullLogger.Instance; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs index 9cdfaf7fb7..9bd5be4cc5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.VirtualFileSystem; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers @@ -8,17 +9,19 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers public class AbpTagHelperScriptService : AbpTagHelperResourceService { public AbpTagHelperScriptService( - IBundleManager bundleManager, - IHybridWebRootFileProvider webRootFileProvider + IBundleManager bundleManager, + IHybridWebRootFileProvider webRootFileProvider, + IOptions options ) : base( - bundleManager, - webRootFileProvider) + bundleManager, + webRootFileProvider, + options) { } protected override void CreateBundle(string bundleName, List bundleItems) { - BundleManager.CreateScriptBundle( + Options.StyleBundles.TryAdd( bundleName, configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) ); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs index 49239f905e..74d1a62b7f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.VirtualFileSystem; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers @@ -9,16 +10,18 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers { public AbpTagHelperStyleService( IBundleManager bundleManager, - IHybridWebRootFileProvider webRootFileProvider + IHybridWebRootFileProvider webRootFileProvider, + IOptions options ) : base( bundleManager, - webRootFileProvider) + webRootFileProvider, + options) { } protected override void CreateBundle(string bundleName, List bundleItems) { - BundleManager.CreateStyleBundle( + Options.StyleBundles.TryAdd( bundleName, configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) );