Browse Source

Ensure to add dependencies of bundle contributors.

pull/746/head
Halil ibrahim Kalkan 8 years ago
parent
commit
9133b875bd
  1. 38
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs
  2. 5
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/AbpAspNetCoreMvcUIBasicThemeModule.cs

38
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs

@ -1,8 +1,8 @@
using System; using JetBrains.Annotations;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
@ -18,6 +18,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
public void Add(BundleContributor contributor) public void Add(BundleContributor contributor)
{ {
foreach (var dependedType in GetDirectDependencies(contributor.GetType()))
{
AddWithDependencies(dependedType);
}
_contributors.Add(contributor); _contributors.Add(contributor);
} }
@ -39,11 +44,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
return _contributors.ToImmutableList(); return _contributors.ToImmutableList();
} }
private bool IsAlreadyAdded(Type contributorType)
{
return _contributors.Any(c => c.GetType() == contributorType);
}
private void AddWithDependencies(Type contributorType) private void AddWithDependencies(Type contributorType)
{ {
if (IsAlreadyAdded(contributorType)) if (IsAlreadyAdded(contributorType))
@ -51,20 +51,28 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
return; return;
} }
foreach (var dependedType in GetDirectDependencies(contributorType))
{
AddWithDependencies(dependedType); //Recursive call
}
AddInstanceToContributors(contributorType);
}
private IEnumerable<Type> GetDirectDependencies(Type contributorType)
{
var dependsOnAttributes = contributorType var dependsOnAttributes = contributorType
.GetCustomAttributes(true) .GetCustomAttributes(true)
.OfType<IDependedTypesProvider>() .OfType<IDependedTypesProvider>()
.ToList(); .ToList();
foreach (var dependsOnAttribute in dependsOnAttributes) return dependsOnAttributes
{ .SelectMany(a => a.GetDependedTypes());
foreach (var dependedType in dependsOnAttribute.GetDependedTypes()) }
{
AddWithDependencies(dependedType); //Recursive call
}
}
AddInstanceToContributors(contributorType); private bool IsAlreadyAdded(Type contributorType)
{
return _contributors.Any(c => c.GetType() == contributorType);
} }
private void AddInstanceToContributors(Type contributorType) private void AddInstanceToContributors(Type contributorType)

5
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/AbpAspNetCoreMvcUIBasicThemeModule.cs

@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Toolbars; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Toolbars;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
@ -46,7 +45,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic
{ {
bundle bundle
.AddBaseBundles(StandardBundles.Styles.Global) .AddBaseBundles(StandardBundles.Styles.Global)
.AddContributors(new BasicThemeGlobalStyleContributor()); .AddContributors(typeof(BasicThemeGlobalStyleContributor));
}); });
options options

Loading…
Cancel
Save