Skip to content

Commit 389e2ec

Browse files
committed
Add docs for ViewCount module
1 parent 72514dc commit 389e2ec

6 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
namespace OrchardCoreContrib.ViewCount.Handlers;
22

3+
/// <summary>
4+
/// Defines methods for handling view count events for content.
5+
/// </summary>
36
public interface IViewCountContentHandler
47
{
8+
/// <summary>
9+
/// Occurs before the content is viewed.
10+
/// </summary>
11+
/// <param name="context">The <see cref="ViewCountContentContext"/> that identifies the content to record the view for. Cannot be
12+
/// <c>null</c>.</param>
13+
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
514
Task ViewingAsync(ViewCountContentContext context);
615

16+
/// <summary>
17+
/// Occurs after the content is viewed.
18+
/// </summary>
19+
/// <param name="context">The context containing information about the content whose view count should be updated. Must not be
20+
/// <c>null</c>.</param>
21+
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
722
Task ViewedAsync(ViewCountContentContext context);
823
}

src/OrchardCoreContrib.ViewCount/Handlers/ViewCountContentContext.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33

44
namespace OrchardCoreContrib.ViewCount.Handlers;
55

6+
/// <summary>
7+
/// Represents a content context that includes a count of items within a collection.
8+
/// </summary>
9+
/// <remarks>Use <see cref="ViewCountContentContext"/> to associate a specific item of content with a count value,
10+
/// such as the number of times the content has been viewed or the number of related items.</remarks>
611
public class ViewCountContentContext(ContentItem contentItem, int count) : ContentContextBase(contentItem)
712
{
13+
/// <summary>
14+
/// Gets or sets the number of items contained in the collection.
15+
/// </summary>
816
public int Count { get; set; } = count;
917
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
namespace OrchardCoreContrib.ViewCount.Handlers;
22

3+
/// <summary>
4+
/// Provides a base implementation for handling view count events for content items.
5+
/// </summary>
36
public abstract class ViewCountContentHandlerBase : IViewCountContentHandler
47
{
8+
/// <inheritdoc/>
59
public virtual Task ViewingAsync(ViewCountContentContext context) => Task.CompletedTask;
610

11+
/// <inheritdoc/>
712
public virtual Task ViewedAsync(ViewCountContentContext context) => Task.CompletedTask;
813
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
using OrchardCore.ContentManagement;
22

33
namespace OrchardCoreContrib.ViewCount.Models;
4+
5+
/// <summary>
6+
/// Represents a content part that tracks the number of times an item has been viewed.
7+
/// </summary>
8+
/// <remarks>Use <see cref="ViewCountPart"/> to associate a view count with content items, enabling features such
9+
/// as analytics or popularity tracking.</remarks>
410
public class ViewCountPart : ContentPart
511
{
12+
/// <summary>
13+
/// Gets or sets the number of items contained in the collection.
14+
/// </summary>
615
public int Count { get; set; }
716
}

src/OrchardCoreContrib.ViewCount/Services/IViewCountService.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
22

33
namespace OrchardCoreContrib.ViewCount.Services;
44

5+
/// <summary>
6+
/// Defines methods for retrieving and recording view counts for content items.
7+
/// </summary>
8+
/// <remarks>Implementations of this interface provide functionality to track how many times a content item has
9+
/// been viewed and to record new views. This is typically used for analytics, popularity metrics, or display purposes
10+
/// in content management scenarios.</remarks>
511
public interface IViewCountService
612
{
13+
/// <summary>
14+
/// Returns the total number of views recorded for the specified content item.
15+
/// </summary>
16+
/// <param name="contentItem">The content item for which to retrieve the view count. Cannot be <c>null</c>.</param>
17+
/// <returns>The number of times the specified content item has been viewed. Returns 0 if no views have been recorded.</returns>
718
int GetViewsCount(ContentItem contentItem);
819

20+
/// <summary>
21+
/// Increments the views number for the specified content item asynchronously in the current view context.
22+
/// </summary>
23+
/// <param name="contentItem">The content item to be displayed. Cannot be null.</param>
24+
/// <returns>A task that represents the asynchronous display operation.</returns>
925
Task ViewAsync(ContentItem contentItem);
1026
}

src/OrchardCoreContrib.ViewCount/Services/ViewCountService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77

88
namespace OrchardCoreContrib.ViewCount.Services;
99

10+
/// <summary>
11+
/// Provides functionality for tracking and updating view counts on content items.
12+
/// </summary>
13+
/// <remarks>The <see cref="ViewCountService"/> enables retrieval and incrementing of view counts for content
14+
/// items. It coordinates with registered <see cref="IViewCountContentHandler"/> instances to allow custom logic to be
15+
/// executed before and after a view is recorded. This service is typically used to monitor content popularity or
16+
/// engagement.
17+
/// </remarks>
1018
public class ViewCountService(
1119
IContentManager contentManager,
1220
IEnumerable<IViewCountContentHandler> handlers,
1321
ILogger<ViewCountService> logger) : IViewCountService
1422
{
23+
/// <inheritdoc/>
1524
public int GetViewsCount(ContentItem contentItem)
1625
{
1726
Guard.ArgumentNotNull(contentItem, nameof(contentItem));
@@ -21,6 +30,7 @@ public int GetViewsCount(ContentItem contentItem)
2130
return viewCountPart?.Count ?? 0;
2231
}
2332

33+
/// <inheritdoc/>
2434
public async Task ViewAsync(ContentItem contentItem)
2535
{
2636
Guard.ArgumentNotNull(contentItem, nameof(contentItem));

0 commit comments

Comments
 (0)