diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml
index 8b33bafdde..9c91553b33 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml
@@ -1,13 +1,14 @@
@using Volo.Abp.AspNetCore.Mvc.AntiForgery
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.MainNavbar
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.PageAlerts
+@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Components
@inject IAbpAntiForgeryManager AbpAntiForgeryManager
@inject IBrandingProvider BrandingProvider
@{
Layout = null;
AbpAntiForgeryManager.SetCookie();
- var containerClass = ViewBag.FluidLayout == true ? "container-fluid" : "container";
+ var containerClass = ViewBag.FluidLayout == true ? "container-fluid" : "container"; //TODO: Better and type-safe options
}
@@ -19,7 +20,7 @@
@(ViewBag.Title == null ? BrandingProvider.AppName : ViewBag.Title)
-
+
@@ -30,12 +31,11 @@
@(await Component.InvokeAsync())
- @* TODO: Create option to select 'container' or 'container-fluid' *@
@(await Component.InvokeAsync
())
@RenderBody()
-
+
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml
index 920a8edfb5..f284d78de3 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml
@@ -1,6 +1,6 @@
@using Volo.Abp.AspNetCore.Mvc.AntiForgery
-@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.MainNavbar
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.PageAlerts
+@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Components
@inject IAbpAntiForgeryManager AbpAntiForgeryManager
@inject IBrandingProvider BrandingProvider
@@ -18,7 +18,7 @@
@(ViewBag.Title == null ? BrandingProvider.AppName : ViewBag.Title)
-
+
@@ -31,7 +31,7 @@
@RenderBody()
-
+
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs
index bf77e4e092..530a0eda59 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/AbpAspNetCoreMvcUiThemeSharedModule.cs
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
+using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
@@ -22,42 +23,13 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared
{
options
.StyleBundles
- .Add("GlobalStyles")
- .AddFiles(
- "/libs/font-awesome/css/font-awesome.css",
- "/libs/bootstrap/css/bootstrap.css",
- "/libs/datatables.net-bs4/css/dataTables.bootstrap4.css",
- "/libs/toastr/toastr.min.css",
-
- "/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables.css"
- );
+ .Add(StandardBundles.Styles.Global)
+ .AddContributors(typeof(SharedThemeGlobalStyleContributor));
options
.ScriptBundles
- .Add("GlobalScripts")
- .AddFiles(
- "/libs/jquery/jquery.js",
- "/libs/bootstrap/js/bootstrap.bundle.js",
- "/libs/jquery-validation/jquery.validate.js",
- "/libs/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js",
- "/libs/jquery-form/jquery.form.min.js",
- "/libs/datatables.net/js/jquery.dataTables.js",
- "/libs/datatables.net-bs4/js/dataTables.bootstrap4.js",
- "/libs/sweetalert/sweetalert.min.js",
- "/libs/toastr/toastr.min.js",
-
- "/libs/abp/core/abp.js",
- "/libs/abp/jquery/abp.dom.js",
- "/libs/abp/jquery/abp.ajax.js",
- "/libs/abp/jquery/abp.resource-loader.js",
- "/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery/jquery-extensions.js",
- "/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js",
- "/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/dom-event-handlers.js",
- "/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/modal-manager.js",
- "/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables-extensions.js",
- "/libs/abp/aspnetcore.mvc.ui.theme.shared/sweetalert/abp-sweetalert.js",
- "/libs/abp/aspnetcore.mvc.ui.theme.shared/toastr/abp-toastr.js"
- );
+ .Add(StandardBundles.Scripts.Global)
+ .AddContributors(typeof(SharedThemeGlobalScriptContributor));
});
services.AddAssemblyOf();
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs
new file mode 100644
index 0000000000..8cb16f54d4
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs
@@ -0,0 +1,37 @@
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap;
+using Volo.Abp.Modularity;
+
+namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling
+{
+ [DependsOn(
+ typeof(BootstrapScriptBundleContributor)
+ )]
+ public class SharedThemeGlobalScriptContributor : BundleContributor
+ {
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.AddRange(new[]
+ { //TODO: Create seperated contributors!
+ "/libs/jquery-validation/jquery.validate.js",
+ "/libs/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js",
+ "/libs/jquery-form/jquery.form.min.js",
+ "/libs/datatables.net/js/jquery.dataTables.js",
+ "/libs/datatables.net-bs4/js/dataTables.bootstrap4.js",
+ "/libs/sweetalert/sweetalert.min.js",
+ "/libs/toastr/toastr.min.js",
+ "/libs/abp/core/abp.js",
+ "/libs/abp/jquery/abp.dom.js",
+ "/libs/abp/jquery/abp.ajax.js",
+ "/libs/abp/jquery/abp.resource-loader.js",
+ "/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery/jquery-extensions.js",
+ "/libs/abp/aspnetcore.mvc.ui.theme.shared/jquery-form/jquery-form-extensions.js",
+ "/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/dom-event-handlers.js",
+ "/libs/abp/aspnetcore.mvc.ui.theme.shared/bootstrap/modal-manager.js",
+ "/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables-extensions.js",
+ "/libs/abp/aspnetcore.mvc.ui.theme.shared/sweetalert/abp-sweetalert.js",
+ "/libs/abp/aspnetcore.mvc.ui.theme.shared/toastr/abp-toastr.js"
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs
new file mode 100644
index 0000000000..bc7bc1355d
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs
@@ -0,0 +1,23 @@
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap;
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.DatatablesNetBs4;
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.FontAwesome;
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Toastr;
+using Volo.Abp.Modularity;
+
+namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling
+{
+ [DependsOn(
+ typeof(BootstrapStyleBundleContributor),
+ typeof(FontAwesomeStyleBundleContributor),
+ typeof(ToastrStyleBundleContributor),
+ typeof(DatatablesNetBs4StyleBundleContributor)
+ )]
+ public class SharedThemeGlobalStyleContributor : BundleContributor
+ {
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.Add("/libs/abp/aspnetcore.mvc.ui.theme.shared/datatables/datatables.css");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/StandardBundles.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/StandardBundles.cs
new file mode 100644
index 0000000000..4bbb95b908
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/StandardBundles.cs
@@ -0,0 +1,15 @@
+namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling
+{
+ public class StandardBundles
+ {
+ public static class Styles
+ {
+ public static string Global = "Global";
+ }
+
+ public static class Scripts
+ {
+ public static string Global = "Global";
+ }
+ }
+}
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollectionExtensions.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollectionExtensions.cs
index 65967a2045..7a79fa5941 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollectionExtensions.cs
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollectionExtensions.cs
@@ -1,12 +1,40 @@
-using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Contributors;
+using System;
+using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
public static class BundleConfigurationExtensions
{
- public static void AddFiles(this BundleConfiguration bundleConfiguration, params string[] files)
+ public static BundleConfiguration AddFiles(this BundleConfiguration bundleConfiguration, params string[] files)
{
- bundleConfiguration.Contributors.Add(new SimpleBundleContributor(files));
+ bundleConfiguration.Contributors.AddFiles(files);
+ return bundleConfiguration;
+ }
+
+ public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params IBundleContributor[] contributors)
+ {
+ if (!contributors.IsNullOrEmpty())
+ {
+ foreach (var contributor in contributors)
+ {
+ bundleConfiguration.Contributors.Add(contributor);
+ }
+ }
+
+ return bundleConfiguration;
+ }
+
+ public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params Type[] contributorTypes)
+ {
+ if (!contributorTypes.IsNullOrEmpty())
+ {
+ foreach (var contributorType in contributorTypes)
+ {
+ bundleConfiguration.Contributors.Add(contributorType);
+ }
+ }
+
+ return bundleConfiguration;
}
}
}
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs
index 9b43a8fb74..739104537e 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs
@@ -4,12 +4,12 @@
{
public string Name { get; }
- public BundleContributorList Contributors { get; }
+ public BundleContributorCollection Contributors { get; }
public BundleConfiguration(string name)
{
Name = name;
- Contributors = new BundleContributorList();
+ Contributors = new BundleContributorCollection();
}
}
}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollection.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationCollection.cs
similarity index 79%
rename from src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollection.cs
rename to src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationCollection.cs
index 7b9afd5d08..2770305aa5 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollection.cs
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationCollection.cs
@@ -4,11 +4,11 @@ using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
- public class BundleCollection
+ public class BundleConfigurationCollection
{
private readonly ConcurrentDictionary _bundleContributors;
- public BundleCollection()
+ public BundleConfigurationCollection()
{
_bundleContributors = new ConcurrentDictionary();
}
@@ -30,6 +30,12 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
return _bundleContributors[bundleName];
}
+ public BundleConfiguration GetOrNull(string bundleName)
+ {
+ _bundleContributors.TryGetValue(bundleName, out var bundleConfiguration);
+ return bundleConfiguration;
+ }
+
public BundleConfiguration GetOrAdd(string bundleName)
{
return GetOrAdd(bundleName, c => { });
@@ -47,21 +53,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
});
}
- public List GetFiles(string bundleName)
- {
- CheckBundle(bundleName);
-
- var files = new List();
-
- var bundleConfiguration = _bundleContributors[bundleName];
- foreach (var contributor in bundleConfiguration.Contributors)
- {
- contributor.Contribute(files);
- }
-
- return files;
- }
-
private void CheckBundle(string bundleName)
{
if (!_bundleContributors.ContainsKey(bundleName))
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs
new file mode 100644
index 0000000000..31edaa97c1
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using Volo.Abp.AspNetCore.Mvc.UI.Theming;
+
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
+{
+ public class BundleConfigurationContext : IBundleConfigurationContext
+ {
+ public List Files { get; }
+ public ITheme Theme { get; }
+ public IServiceProvider ServiceProvider { get; }
+
+ public BundleConfigurationContext(List files, ITheme theme, IServiceProvider serviceProvider)
+ {
+ Files = files;
+ Theme = theme;
+ ServiceProvider = serviceProvider;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributor.cs
new file mode 100644
index 0000000000..ba5cb820cb
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributor.cs
@@ -0,0 +1,7 @@
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
+{
+ public abstract class BundleContributor : IBundleContributor
+ {
+ public abstract void ConfigureBundle(BundleConfigurationContext context);
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorCollection.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorCollection.cs
new file mode 100644
index 0000000000..1877fe6ac3
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorCollection.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Linq;
+using JetBrains.Annotations;
+using Volo.Abp.Modularity;
+
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
+{
+ public class BundleContributorCollection
+ {
+ private readonly List _contributors;
+
+ public BundleContributorCollection()
+ {
+ _contributors = new List();
+ }
+
+ public void Add(IBundleContributor contributor)
+ {
+ _contributors.Add(contributor);
+ }
+
+ public void Add()
+ where TContributor : IBundleContributor, new()
+ {
+ Add(typeof(TContributor));
+ }
+
+ public void Add([NotNull] Type contributorType)
+ {
+ Check.NotNull(contributorType, nameof(contributorType));
+ if (!typeof(IBundleContributor).IsAssignableFrom(contributorType))
+ {
+ throw new AbpException($"Given {nameof(contributorType)} ({contributorType.AssemblyQualifiedName}) should implement the {typeof(IBundleContributor).AssemblyQualifiedName} interface!");
+ }
+
+ if (IsAlreadyAdded(contributorType))
+ {
+ throw new AbpException($"Given {nameof(contributorType)} ({contributorType.AssemblyQualifiedName}) is already added before! If you want to ensure that a contributor is added, create your own contributor and depend on the contributor you want to ensure that it's added.");
+ }
+
+ AddWithDependencies(contributorType);
+ }
+
+ public IReadOnlyList GetAll()
+ {
+ return _contributors.ToImmutableList();
+ }
+
+ private bool IsAlreadyAdded(Type contributorType)
+ {
+ return _contributors.Any(c => c.GetType() == contributorType);
+ }
+
+ private void AddWithDependencies(Type contributorType)
+ {
+ var dependsOnAttributes = contributorType
+ .GetCustomAttributes(true)
+ .OfType()
+ .ToList();
+
+ foreach (var dependsOnAttribute in dependsOnAttributes)
+ {
+ foreach (var dependedType in dependsOnAttribute.GetDependedTypes())
+ {
+ AddWithDependencies(dependedType); //Recursive call
+
+ if (!IsAlreadyAdded(dependedType))
+ {
+ AddInstanceToContributors(dependedType);
+ }
+ }
+ }
+
+ AddInstanceToContributors(contributorType);
+ }
+
+ private void AddInstanceToContributors(Type contributorType)
+ {
+ try
+ {
+ _contributors.Add((IBundleContributor)Activator.CreateInstance(contributorType));
+ }
+ catch (Exception ex)
+ {
+ throw new AbpException($"Can not instantiate {contributorType.AssemblyQualifiedName}", ex);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorList.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorList.cs
deleted file mode 100644
index c527ed7972..0000000000
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorList.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System.Collections.Generic;
-
-namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
-{
- public class BundleContributorList : List
- {
-
- }
-}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorListExtensions.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorListExtensions.cs
new file mode 100644
index 0000000000..116cab0ade
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleContributorListExtensions.cs
@@ -0,0 +1,10 @@
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
+{
+ public static class BundleContributorListExtensions
+ {
+ public static void AddFiles(this BundleContributorCollection contributors, params string[] files)
+ {
+ contributors.Add(new SimpleBundleContributor(files));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs
index 77070083bf..4341e8633f 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs
@@ -2,26 +2,35 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
+using Volo.Abp.AspNetCore.Mvc.UI.Theming;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
+ //TODO: Do not make this singleton (since it's using scoped services), instead separate a singleton bundlecache!
public class BundleManager : IBundleManager, ISingletonDependency
{
private readonly BundlingOptions _options;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IBundler _bundler;
+ private readonly IThemeManager _themeManager;
+ private readonly IServiceProvider _serviceProvider;
private readonly ConcurrentDictionary _cache;
public BundleManager(
IOptions options,
IHostingEnvironment hostingEnvironment,
- IBundler bundler)
+ IBundler bundler,
+ IThemeManager themeManager,
+ IServiceProvider serviceProvider)
{
_hostingEnvironment = hostingEnvironment;
_bundler = bundler;
+ _themeManager = themeManager;
+ _serviceProvider = serviceProvider;
_options = options.Value;
_cache = new ConcurrentDictionary();
@@ -29,12 +38,12 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
public List GetStyleBundleFiles(string bundleName)
{
- return _options.StyleBundles.GetFiles(bundleName);
+ return GetFiles(_options.StyleBundles.Get(bundleName));
}
public List GetScriptBundleFiles(string bundleName)
{
- return _options.ScriptBundles.GetFiles(bundleName);
+ return GetFiles(_options.ScriptBundles.Get(bundleName));
}
public void CreateStyleBundle(string bundleName, Action configureAction)
@@ -46,5 +55,27 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
_options.ScriptBundles.GetOrAdd(bundleName, configureAction);
}
+
+ protected virtual List GetFiles(BundleConfiguration bundleConfiguration)
+ {
+ //TODO: Caching, Bundling & Minifying!
+
+ using (var scope = _serviceProvider.CreateScope())
+ {
+
+ var context = new BundleConfigurationContext(
+ new List(),
+ _themeManager.CurrentTheme,
+ scope.ServiceProvider
+ );
+
+ foreach (var contributor in bundleConfiguration.Contributors.GetAll())
+ {
+ contributor.ConfigureBundle(context);
+ }
+
+ return context.Files;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundlingOptions.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundlingOptions.cs
index 29ea934506..7c5d02f3b5 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundlingOptions.cs
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundlingOptions.cs
@@ -2,14 +2,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
public class BundlingOptions
{
- public BundleCollection StyleBundles { get; set; }
+ public BundleConfigurationCollection StyleBundles { get; set; }
- public BundleCollection ScriptBundles { get; set; }
+ public BundleConfigurationCollection ScriptBundles { get; set; }
public BundlingOptions()
{
- StyleBundles = new BundleCollection();
- ScriptBundles = new BundleCollection();
+ StyleBundles = new BundleConfigurationCollection();
+ ScriptBundles = new BundleConfigurationCollection();
}
}
}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Contributors/SimpleBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Contributors/SimpleBundleContributor.cs
deleted file mode 100644
index 4ba6e8b4c4..0000000000
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Contributors/SimpleBundleContributor.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Contributors
-{
- public class SimpleBundleContributor : IBundleContributor
- {
- public string[] Files { get; }
-
- public SimpleBundleContributor(params string[] files)
- {
- Files = files ?? Array.Empty();
- }
-
- public void Contribute(List files)
- {
- files.AddRange(Files);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs
new file mode 100644
index 0000000000..291e163a98
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs
@@ -0,0 +1,13 @@
+using System.Collections.Generic;
+using Volo.Abp.AspNetCore.Mvc.UI.Theming;
+using Volo.Abp.DependencyInjection;
+
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
+{
+ public interface IBundleConfigurationContext : IServiceProviderAccessor
+ {
+ List Files { get; }
+
+ ITheme Theme { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleContributor.cs
index 78e502fb61..05306e38c8 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleContributor.cs
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleContributor.cs
@@ -1,9 +1,7 @@
-using System.Collections.Generic;
-
-namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
public interface IBundleContributor
{
- void Contribute(List files);
+ void ConfigureBundle(BundleConfigurationContext context);
}
}
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Bootstrap/BootstrapScriptBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Bootstrap/BootstrapScriptBundleContributor.cs
new file mode 100644
index 0000000000..b908274ec2
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Bootstrap/BootstrapScriptBundleContributor.cs
@@ -0,0 +1,14 @@
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.JQuery;
+using Volo.Abp.Modularity;
+
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap
+{
+ [DependsOn(typeof(JQueryScriptBundleContributor))]
+ public class BootstrapScriptBundleContributor : BundleContributor
+ {
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.Add("/libs/bootstrap/js/bootstrap.bundle.js");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Bootstrap/BootstrapStyleBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Bootstrap/BootstrapStyleBundleContributor.cs
new file mode 100644
index 0000000000..bb98f05deb
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Bootstrap/BootstrapStyleBundleContributor.cs
@@ -0,0 +1,10 @@
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap
+{
+ public class BootstrapStyleBundleContributor : BundleContributor
+ {
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.Add("/libs/bootstrap/css/bootstrap.css");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/DatatablesNetBs4/DatatablesNetBs4StyleBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/DatatablesNetBs4/DatatablesNetBs4StyleBundleContributor.cs
new file mode 100644
index 0000000000..ecbcc77e73
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/DatatablesNetBs4/DatatablesNetBs4StyleBundleContributor.cs
@@ -0,0 +1,14 @@
+using Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Bootstrap;
+using Volo.Abp.Modularity;
+
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.DatatablesNetBs4
+{
+ [DependsOn(typeof(BootstrapStyleBundleContributor))]
+ public class DatatablesNetBs4StyleBundleContributor : BundleContributor
+ {
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.Add("/libs/datatables.net-bs4/css/dataTables.bootstrap4.css");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/FontAwesome/BootstrapStyleBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/FontAwesome/BootstrapStyleBundleContributor.cs
new file mode 100644
index 0000000000..0907b37141
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/FontAwesome/BootstrapStyleBundleContributor.cs
@@ -0,0 +1,10 @@
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.FontAwesome
+{
+ public class FontAwesomeStyleBundleContributor : BundleContributor
+ {
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.Add("/libs/font-awesome/css/font-awesome.css");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/JQuery/JQueryScriptBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/JQuery/JQueryScriptBundleContributor.cs
new file mode 100644
index 0000000000..c6f555fff7
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/JQuery/JQueryScriptBundleContributor.cs
@@ -0,0 +1,10 @@
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.JQuery
+{
+ public class JQueryScriptBundleContributor : BundleContributor
+ {
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.Add("/libs/jquery/jquery.js");
+ }
+ }
+}
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Toastr/ToastrStyleBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Toastr/ToastrStyleBundleContributor.cs
new file mode 100644
index 0000000000..2b8c75294b
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/Libraries/Toastr/ToastrStyleBundleContributor.cs
@@ -0,0 +1,10 @@
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Libraries.Toastr
+{
+ public class ToastrStyleBundleContributor : BundleContributor
+ {
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.Add("/libs/toastr/toastr.min.css");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/SimpleBundleContributor.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/SimpleBundleContributor.cs
new file mode 100644
index 0000000000..470fb05046
--- /dev/null
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/SimpleBundleContributor.cs
@@ -0,0 +1,19 @@
+using System;
+
+namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
+{
+ public class SimpleBundleContributor : BundleContributor
+ {
+ public string[] Files { get; }
+
+ public SimpleBundleContributor(params string[] files)
+ {
+ Files = files ?? Array.Empty();
+ }
+
+ public override void ConfigureBundle(BundleConfigurationContext context)
+ {
+ context.Files.AddRange(Files);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpScriptBundle/AbpStyleBundleViewComponent.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpScriptBundle/AbpStyleBundleViewComponent.cs
deleted file mode 100644
index b2119020aa..0000000000
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpScriptBundle/AbpStyleBundleViewComponent.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Microsoft.AspNetCore.Mvc;
-using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
-
-namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpScriptBundle
-{
- public class AbpScriptBundleViewComponent : AbpViewComponent
- {
- private readonly IBundleManager _bundleManager;
-
- public AbpScriptBundleViewComponent(IBundleManager bundleManager)
- {
- _bundleManager = bundleManager;
- }
-
- public IViewComponentResult Invoke(string name)
- {
- var files = _bundleManager.GetScriptBundleFiles(name);
- return View(files);
- }
- }
-}
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpScriptBundle/Default.cshtml b/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpScriptBundle/Default.cshtml
deleted file mode 100644
index 0e62858fc4..0000000000
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpScriptBundle/Default.cshtml
+++ /dev/null
@@ -1,5 +0,0 @@
-@model List
-@foreach (var scriptFile in Model)
-{
-
-}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpStyleBundle/AbpStyleBundleViewComponent.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpStyleBundle/AbpStyleBundleViewComponent.cs
deleted file mode 100644
index 09144bfc3a..0000000000
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpStyleBundle/AbpStyleBundleViewComponent.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Microsoft.AspNetCore.Mvc;
-using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
-
-namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpStyleBundle
-{
- public class AbpStyleBundleViewComponent : AbpViewComponent
- {
- private readonly IBundleManager _bundleManager;
-
- public AbpStyleBundleViewComponent(IBundleManager bundleManager)
- {
- _bundleManager = bundleManager;
- }
-
- public IViewComponentResult Invoke(string name)
- {
- var files = _bundleManager.GetStyleBundleFiles(name);
- return View(files);
- }
- }
-}
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpStyleBundle/Default.cshtml b/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpStyleBundle/Default.cshtml
deleted file mode 100644
index 34089900ed..0000000000
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/Views/Shared/Components/AbpStyleBundle/Default.cshtml
+++ /dev/null
@@ -1,5 +0,0 @@
-@model List
-@foreach (var styleFile in Model)
-{
-
-}
\ No newline at end of file
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj b/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj
index 904a527c9b..f2733610fa 100644
--- a/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj
+++ b/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj
@@ -10,10 +10,6 @@
Volo.Abp.AspNetCore.Mvc
-
-
-
-
diff --git a/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs b/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs
index 149a4efa6b..488294c77f 100644
--- a/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs
+++ b/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs
@@ -50,8 +50,7 @@ namespace System.Collections.Generic
/// Value if found, default if can not found.
public static TValue GetOrDefault(this IDictionary dictionary, TKey key)
{
- TValue obj;
- return dictionary.TryGetValue(key, out obj) ? obj : default;
+ return dictionary.TryGetValue(key, out var obj) ? obj : default;
}
///
@@ -64,8 +63,7 @@ namespace System.Collections.Generic
/// Value if found, default if can not found.
public static TValue GetOrDefault(this IReadOnlyDictionary dictionary, TKey key)
{
- TValue obj;
- return dictionary.TryGetValue(key, out obj) ? obj : default;
+ return dictionary.TryGetValue(key, out var obj) ? obj : default;
}
///
diff --git a/src/Volo.Abp.Core/Volo/Abp/Modularity/AbpModuleHelper.cs b/src/Volo.Abp.Core/Volo/Abp/Modularity/AbpModuleHelper.cs
index ace08b293e..d58483811b 100644
--- a/src/Volo.Abp.Core/Volo/Abp/Modularity/AbpModuleHelper.cs
+++ b/src/Volo.Abp.Core/Volo/Abp/Modularity/AbpModuleHelper.cs
@@ -22,11 +22,11 @@ namespace Volo.Abp.Modularity
var dependencyDescriptors = moduleType
.GetCustomAttributes()
- .OfType();
+ .OfType();
foreach (var descriptor in dependencyDescriptors)
{
- foreach (var dependedModuleType in descriptor.GetDependedModuleTypes())
+ foreach (var dependedModuleType in descriptor.GetDependedTypes())
{
dependencies.AddIfNotContains(dependedModuleType);
}
diff --git a/src/Volo.Abp.Core/Volo/Abp/Modularity/DependsOnAttribute.cs b/src/Volo.Abp.Core/Volo/Abp/Modularity/DependsOnAttribute.cs
index 5cd3a2baaf..6d41ae1645 100644
--- a/src/Volo.Abp.Core/Volo/Abp/Modularity/DependsOnAttribute.cs
+++ b/src/Volo.Abp.Core/Volo/Abp/Modularity/DependsOnAttribute.cs
@@ -4,30 +4,22 @@ using JetBrains.Annotations;
namespace Volo.Abp.Modularity
{
///
- /// Used to define dependencies of an ABP module to other modules.
- /// It should be used for a class implements .
+ /// Used to define dependencies of a type.
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
- public class DependsOnAttribute : Attribute, IDependedModuleTypesProvider
+ public class DependsOnAttribute : Attribute, IDependedTypesProvider
{
- ///
- /// Types of depended modules.
- ///
[NotNull]
- public Type[] DependedModuleTypes { get; }
+ public Type[] DependedTypes { get; }
- ///
- /// Used to define dependencies of an ABP module to other modules.
- ///
- /// Types of depended modules
- public DependsOnAttribute(params Type[] dependedModuleTypes)
+ public DependsOnAttribute(params Type[] dependedTypes)
{
- DependedModuleTypes = dependedModuleTypes ?? new Type[0];
+ DependedTypes = dependedTypes ?? new Type[0];
}
- public virtual Type[] GetDependedModuleTypes()
+ public virtual Type[] GetDependedTypes()
{
- return DependedModuleTypes;
+ return DependedTypes;
}
}
}
\ No newline at end of file
diff --git a/src/Volo.Abp.Core/Volo/Abp/Modularity/IDependedModuleTypesProvider.cs b/src/Volo.Abp.Core/Volo/Abp/Modularity/IDependedTypesProvider.cs
similarity index 54%
rename from src/Volo.Abp.Core/Volo/Abp/Modularity/IDependedModuleTypesProvider.cs
rename to src/Volo.Abp.Core/Volo/Abp/Modularity/IDependedTypesProvider.cs
index fe6934ba67..94b906cd96 100644
--- a/src/Volo.Abp.Core/Volo/Abp/Modularity/IDependedModuleTypesProvider.cs
+++ b/src/Volo.Abp.Core/Volo/Abp/Modularity/IDependedTypesProvider.cs
@@ -3,9 +3,9 @@ using JetBrains.Annotations;
namespace Volo.Abp.Modularity
{
- public interface IDependedModuleTypesProvider
+ public interface IDependedTypesProvider
{
[NotNull]
- Type[] GetDependedModuleTypes();
+ Type[] GetDependedTypes();
}
}
\ No newline at end of file
diff --git a/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml b/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml
index 89fc9f40de..c1fd7bd82b 100644
--- a/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml
+++ b/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml
@@ -1,4 +1,5 @@
-@{
+@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling
+@{
Layout = null;
var title = "ABP Bootstrap Demo";
if (ViewData["Title"] != null)
@@ -16,8 +17,8 @@
@title
-
- @* TODO: Add to the GlobalStyles bundle! *@
+
+
@RenderSection("styles", false)
@@ -27,7 +28,7 @@
@RenderBody()
-
+
@RenderSection("scripts", false)