Browse Source

Refactor bundling

pull/395/head
Halil ibrahim Kalkan 8 years ago
parent
commit
9bf4e0c412
  1. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs
  2. 10
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs
  3. 7
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs
  4. 9
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs
  5. 13
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs
  6. 9
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs

8
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
/// <param name="bundleName">Bundle name.</param> /// <param name="bundleName">Bundle name.</param>
/// <param name="configureAction">Initial configuration action.</param> /// <param name="configureAction">Initial configuration action.</param>
/// <returns>Returns this object for chained calls.</returns> /// <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)) if (!TryAdd(bundleName, configureAction))
{ {
@ -41,7 +43,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
/// <param name="bundleName">Bundle name.</param> /// <param name="bundleName">Bundle name.</param>
/// <param name="configureAction">Initial configuration action.</param> /// <param name="configureAction">Initial configuration action.</param>
/// <returns>Returns true if added. Returns false if it's already added before.</returns> /// <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)); Check.NotNull(bundleName, nameof(bundleName));

10
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<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() protected virtual bool IsBundlingEnabled()
{ {
switch (Options.Mode) switch (Options.Mode)

7
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; using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{ {
//TODO: Bundle system needs refactoring/redesign
public interface IBundleManager public interface IBundleManager
{ {
IReadOnlyList<string> GetStyleBundleFiles(string bundleName); IReadOnlyList<string> GetStyleBundleFiles(string bundleName);
IReadOnlyList<string> GetScriptBundleFiles(string bundleName); IReadOnlyList<string> GetScriptBundleFiles(string bundleName);
void CreateStyleBundle(string bundleName, Action<BundleConfiguration> configureAction);
void CreateScriptBundle(string bundleName, Action<BundleConfiguration> configureAction);
} }
} }

9
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 System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -16,15 +17,17 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
public ILogger<AbpTagHelperResourceService> Logger { get; set; } public ILogger<AbpTagHelperResourceService> Logger { get; set; }
protected IBundleManager BundleManager { get; } protected IBundleManager BundleManager { get; }
protected IHybridWebRootFileProvider WebRootFileProvider { get; } protected IHybridWebRootFileProvider WebRootFileProvider { get; }
protected readonly BundlingOptions Options;
protected AbpTagHelperResourceService( protected AbpTagHelperResourceService(
IBundleManager bundleManager, IBundleManager bundleManager,
IHybridWebRootFileProvider webRootFileProvider) IHybridWebRootFileProvider webRootFileProvider,
IOptions<BundlingOptions> options)
{ {
BundleManager = bundleManager; BundleManager = bundleManager;
WebRootFileProvider = webRootFileProvider; WebRootFileProvider = webRootFileProvider;
Options = options.Value;
Logger = NullLogger<AbpTagHelperResourceService>.Instance; Logger = NullLogger<AbpTagHelperResourceService>.Instance;
} }

13
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;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.AspNetCore.VirtualFileSystem;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers 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 class AbpTagHelperScriptService : AbpTagHelperResourceService
{ {
public AbpTagHelperScriptService( public AbpTagHelperScriptService(
IBundleManager bundleManager, IBundleManager bundleManager,
IHybridWebRootFileProvider webRootFileProvider IHybridWebRootFileProvider webRootFileProvider,
IOptions<BundlingOptions> options
) : base( ) : base(
bundleManager, bundleManager,
webRootFileProvider) webRootFileProvider,
options)
{ {
} }
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
{ {
BundleManager.CreateScriptBundle( Options.StyleBundles.TryAdd(
bundleName, bundleName,
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration))
); );

9
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;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.AspNetCore.VirtualFileSystem;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
@ -9,16 +10,18 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
{ {
public AbpTagHelperStyleService( public AbpTagHelperStyleService(
IBundleManager bundleManager, IBundleManager bundleManager,
IHybridWebRootFileProvider webRootFileProvider IHybridWebRootFileProvider webRootFileProvider,
IOptions<BundlingOptions> options
) : base( ) : base(
bundleManager, bundleManager,
webRootFileProvider) webRootFileProvider,
options)
{ {
} }
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
{ {
BundleManager.CreateStyleBundle( Options.StyleBundles.TryAdd(
bundleName, bundleName,
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration))
); );

Loading…
Cancel
Save