Refactor bundling

pull/395/head
Halil ibrahim Kalkan 7 years ago
parent 16af2ac271
commit 9bf4e0c412

@ -23,7 +23,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
/// <param name="bundleName">Bundle name.</param>
/// <param name="configureAction">Initial configuration action.</param>
/// <returns>Returns this object for chained calls.</returns>
public BundleConfigurationCollection Add([NotNull] string bundleName, [CanBeNull] Action<BundleConfiguration> configureAction = null)
public BundleConfigurationCollection Add(
[NotNull] string bundleName,
[CanBeNull] Action<BundleConfiguration> configureAction = null)
{
if (!TryAdd(bundleName, configureAction))
{
@ -41,7 +43,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
/// <param name="bundleName">Bundle name.</param>
/// <param name="configureAction">Initial configuration action.</param>
/// <returns>Returns true if added. Returns false if it's already added before.</returns>
public bool TryAdd([NotNull] string bundleName, [CanBeNull] Action<BundleConfiguration> configureAction = null)
public bool TryAdd(
[NotNull] string bundleName,
[CanBeNull] Action<BundleConfiguration> configureAction = null)
{
Check.NotNull(bundleName, nameof(bundleName));

@ -142,16 +142,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
);
}
public virtual void CreateStyleBundle(string bundleName, Action<BundleConfiguration> configureAction)
{
Options.StyleBundles.TryAdd(bundleName, configureAction);
}
public virtual void CreateScriptBundle(string bundleName, Action<BundleConfiguration> configureAction)
{
Options.ScriptBundles.TryAdd(bundleName, configureAction);
}
protected virtual bool IsBundlingEnabled()
{
switch (Options.Mode)

@ -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<string> GetStyleBundleFiles(string bundleName);
IReadOnlyList<string> GetScriptBundleFiles(string bundleName);
void CreateStyleBundle(string bundleName, Action<BundleConfiguration> configureAction);
void CreateScriptBundle(string bundleName, Action<BundleConfiguration> configureAction);
}
}

@ -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<AbpTagHelperResourceService> Logger { get; set; }
protected IBundleManager BundleManager { get; }
protected IHybridWebRootFileProvider WebRootFileProvider { get; }
protected readonly BundlingOptions Options;
protected AbpTagHelperResourceService(
IBundleManager bundleManager,
IHybridWebRootFileProvider webRootFileProvider)
IHybridWebRootFileProvider webRootFileProvider,
IOptions<BundlingOptions> options)
{
BundleManager = bundleManager;
WebRootFileProvider = webRootFileProvider;
Options = options.Value;
Logger = NullLogger<AbpTagHelperResourceService>.Instance;
}

@ -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<BundlingOptions> options
) : base(
bundleManager,
webRootFileProvider)
bundleManager,
webRootFileProvider,
options)
{
}
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
{
BundleManager.CreateScriptBundle(
Options.StyleBundles.TryAdd(
bundleName,
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration))
);

@ -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<BundlingOptions> options
) : base(
bundleManager,
webRootFileProvider)
webRootFileProvider,
options)
{
}
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
{
BundleManager.CreateStyleBundle(
Options.StyleBundles.TryAdd(
bundleName,
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration))
);

Loading…
Cancel
Save