Skip to content

Commit 6ca7dc1

Browse files
committed
feat: general improvements and minor bugs
1 parent 2706f03 commit 6ca7dc1

11 files changed

Lines changed: 246 additions & 185 deletions

File tree

src/WebExpress.WebCore/WebAttribute/WebIconAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace WebExpress.WebCore.WebAttribute
88
/// </summary>
99
/// <typeparam name="TIcon">The type of the icon, which must implement the <see cref="IIcon"/> interface.</typeparam>
1010
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
11-
public class WebIconAttribute<TIcon> : Attribute, ISettingPageAttribute, ISettingCategoryAttribute, ISettingGroupAttribute
11+
public class WebIconAttribute<TIcon> : Attribute, ISettingPageAttribute, IPageAttribute, ISettingCategoryAttribute, ISettingGroupAttribute
1212
where TIcon : IIcon
1313
{
1414
/// <summary>

src/WebExpress.WebCore/WebComponent/ComponentActivator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reflection;
44
using WebExpress.WebCore.WebApplication;
55
using WebExpress.WebCore.WebMessage;
6+
using WebExpress.WebCore.WebPage;
67
using WebExpress.WebCore.WebStatusPage;
78

89
namespace WebExpress.WebCore.WebComponent
@@ -261,6 +262,10 @@ public static TComponent CreateInstance<TComponent, TContext>(Type componentType
261262
(
262263
parameter.ParameterType == typeof(IApplicationContext) &&
263264
x.GetType().GetInterfaces().Any(x => x == typeof(IApplicationContext))
265+
) ||
266+
(
267+
parameter.ParameterType == typeof(IPageContext) &&
268+
x.GetType().GetInterfaces().Any(x => x == typeof(IPageContext))
264269
)
265270
)
266271
.FirstOrDefault() ?? null

src/WebExpress.WebCore/WebFragment/FragmentManager.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,28 @@ public IEnumerable<TFragment> GetFragments<TFragment, TSection>(IApplicationCont
414414
}
415415
}
416416

417+
/// <summary>
418+
/// Returns all fragments that belong to a given page.
419+
/// </summary>
420+
/// <typeparam name="TFragment">The fragment type.</typeparam>
421+
/// <typeparam name="TSection">The section where the fragment is embedded.</typeparam>
422+
/// <param name="pageContext">The page context.</param>
423+
/// <returns>An enumeration of the filtered fragments.</returns>
424+
public IEnumerable<TFragment> GetFragments<TFragment, TSection>(IPageContext pageContext)
425+
where TFragment : IFragmentBase
426+
where TSection : ISection
427+
{
428+
var applicationContext = pageContext?.ApplicationContext;
429+
var scopes = pageContext?.Scopes ?? [typeof(IScope)];
430+
431+
var effectiveScopes = (scopes?.Any() == true) ? scopes : [typeof(IScope)];
432+
433+
foreach (var item in _dictionary.GetFragmentItems(applicationContext, typeof(TFragment), typeof(TSection), effectiveScopes))
434+
{
435+
yield return item.CreateInstance<TFragment>(pageContext);
436+
}
437+
}
438+
417439
/// <summary>
418440
/// Returns all fragment contexts that belong to a given application.
419441
/// </summary>

src/WebExpress.WebCore/WebFragment/IFragmentManager.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
4+
using System.Linq;
35
using WebExpress.WebCore.WebApplication;
46
using WebExpress.WebCore.WebComponent;
57
using WebExpress.WebCore.WebHtml;
@@ -92,6 +94,17 @@ public IEnumerable<TFragment> GetFragments<TFragment, TSection>(IApplicationCont
9294
where TFragment : IFragmentBase
9395
where TSection : ISection;
9496

97+
/// <summary>
98+
/// Returns all fragments that belong to a given page.
99+
/// </summary>
100+
/// <typeparam name="TFragment">The fragment type.</typeparam>
101+
/// <typeparam name="TSection">The section where the fragment is embedded.</typeparam>
102+
/// <param name="pageContext">The page context.</param>
103+
/// <returns>An enumeration of the filtered fragments.</returns>
104+
IEnumerable<TFragment> GetFragments<TFragment, TSection>(IPageContext pageContext)
105+
where TFragment : IFragmentBase
106+
where TSection : ISection;
107+
95108
/// <summary>
96109
/// Returns all fragment contexts that belong to a given application.
97110
/// </summary>

0 commit comments

Comments
 (0)