From 60ed3f7a65c6658126feb98b65cb1d811472173e Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Tue, 3 Nov 2020 19:00:06 +0300 Subject: [PATCH] use basebundlecontributer to avoid code duplication --- .../BundleContributer.cs | 19 ++-------- .../BundleContributer.cs | 16 ++------ .../WebAssembly/BundleContributer.cs | 18 ++------- .../Volo.Abp.BlazoriseUI/BundleContributer.cs | 33 ++++++---------- .../Abp/Bundling/BaseBundleContributer.cs | 38 +++++++++++++++++++ .../WebAssembly/BundleContributer.cs | 19 ++-------- 6 files changed, 64 insertions(+), 79 deletions(-) create mode 100644 framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BaseBundleContributer.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BundleContributer.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BundleContributer.cs index 81ff6044b2..666a6e24f5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BundleContributer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BundleContributer.cs @@ -1,26 +1,15 @@ -using System.Collections.Generic; -using Volo.Abp.Bundling; +using Volo.Abp.Bundling; namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme { - public class BundleContributer : IBundleContributer + public class BundleContributer : BaseBundleContributer { - public void AddScripts(List scriptDefinitions) + public override string[] GetStyles() { - - } - - public void AddStyles(List styleDefinitions) - { - var styles = new string[] + return new string[] { "_content/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/libs/abp/css/theme.css", }; - - foreach (var style in styles) - { - styleDefinitions.AddIfNotContains((item) => item.Source == style, () => new BundleDefinition(style)); - } } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/BundleContributer.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/BundleContributer.cs index fa46219c06..d4d8902079 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/BundleContributer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/BundleContributer.cs @@ -3,26 +3,16 @@ using Volo.Abp.Bundling; namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming { - public class BundleContributer : IBundleContributer + public class BundleContributer : BaseBundleContributer { - public void AddScripts(List scriptDefinitions) + public override string[] GetStyles() { - - } - - public void AddStyles(List styleDefinitions) - { - var styles = new string[] + return new string[] { "_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/bootstrap/css/bootstrap.min.css", "_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/fontawesome/css/all.css", "_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/flag-icon/css/flag-icon.css" }; - - foreach (var style in styles) - { - styleDefinitions.AddIfNotContains((item) => item.Source == style, () => new BundleDefinition(style)); - } } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/BundleContributer.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/BundleContributer.cs index 99fcde7b97..693bf8f575 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/BundleContributer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/BundleContributer.cs @@ -1,25 +1,15 @@ -using System.Collections.Generic; -using Volo.Abp.Bundling; +using Volo.Abp.Bundling; namespace Volo.Abp.AspNetCore.Components.WebAssembly { - public class BundleContributer : IBundleContributer + public class BundleContributer : BaseBundleContributer { - public void AddScripts(List scriptDefinitions) + public override string[] GetScripts() { - var scripts = new string[] + return new string[] { "_content/Volo.Abp.AspNetCore.Components.WebAssembly/libs/abp/js/abp.js", }; - - foreach (var script in scripts) - { - scriptDefinitions.AddIfNotContains((item) => item.Source == script, () => new BundleDefinition(script)); - } - } - - public void AddStyles(List styleDefinitions) - { } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/BundleContributer.cs b/framework/src/Volo.Abp.BlazoriseUI/BundleContributer.cs index 2b182f465f..0e72dc1e36 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/BundleContributer.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/BundleContributer.cs @@ -1,37 +1,26 @@ -using System.Collections.Generic; -using Volo.Abp.Bundling; +using Volo.Abp.Bundling; namespace Volo.Abp.BlazoriseUI { - public class BundleContributer : IBundleContributer + public class BundleContributer : BaseBundleContributer { - public void AddScripts(List scriptDefinitions) + public override string[] GetStyles() { - var scripts = new string[] - { - "_content/Blazorise/blazorise.js", - "_content/Blazorise.Bootstrap/blazorise.bootstrap.js" - }; - - foreach (var script in scripts) - { - scriptDefinitions.AddIfNotContains((item) => item.Source == script, () => new BundleDefinition(script)); - } - } - - public void AddStyles(List styleDefinitions) - { - var styles = new string[] + return new string[] { "_content/Blazorise/blazorise.css", "_content/Blazorise.Bootstrap/blazorise.bootstrap.css", "_content/Blazorise.Snackbar/blazorise.snackbar.css" }; + } - foreach (var style in styles) + public override string[] GetScripts() + { + return new string[] { - styleDefinitions.AddIfNotContains((item) => item.Source == style, () => new BundleDefinition(style)); - } + "_content/Blazorise/blazorise.js", + "_content/Blazorise.Bootstrap/blazorise.bootstrap.js" + }; } } } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BaseBundleContributer.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BaseBundleContributer.cs new file mode 100644 index 0000000000..214b021afb --- /dev/null +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BaseBundleContributer.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.Bundling +{ + public class BaseBundleContributer : IBundleContributer + { + public virtual void AddScripts(List scriptDefinitions) + { + var scripts = GetScripts(); + + foreach (var script in scripts) + { + scriptDefinitions.AddIfNotContains((item) => item.Source == script, () => new BundleDefinition(script)); + } + } + + public virtual void AddStyles(List styleDefinitions) + { + var styles = GetStyles(); + + foreach (var style in styles) + { + styleDefinitions.AddIfNotContains((item) => item.Source == style, () => new BundleDefinition(style)); + } + } + + public virtual string[] GetStyles() + { + return Array.Empty(); + } + + public virtual string[] GetScripts() + { + return Array.Empty(); + } + } +} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel.WebAssembly/Volo/Abp/Http/Client/IdentityModel/WebAssembly/BundleContributer.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel.WebAssembly/Volo/Abp/Http/Client/IdentityModel/WebAssembly/BundleContributer.cs index b7932866ad..e4dec37162 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel.WebAssembly/Volo/Abp/Http/Client/IdentityModel/WebAssembly/BundleContributer.cs +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel.WebAssembly/Volo/Abp/Http/Client/IdentityModel/WebAssembly/BundleContributer.cs @@ -1,26 +1,15 @@ -using System.Collections.Generic; -using Volo.Abp.Bundling; +using Volo.Abp.Bundling; namespace Volo.Abp.Http.Client.IdentityModel.WebAssembly { - public class BundleContributer : IBundleContributer + public class BundleContributer : BaseBundleContributer { - public void AddScripts(List scriptDefinitions) + public override string[] GetScripts() { - var scripts = new string[] + return new string[] { "_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js", }; - - foreach (var script in scripts) - { - scriptDefinitions.AddIfNotContains((item) => item.Source == script, () => new BundleDefinition(script)); - } - } - - public void AddStyles(List styleDefinitions) - { - } } }