Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/KSFramework/KSMessaging/Extensions/RegisterMediatorServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public static IServiceCollection AddKSMediator(this IServiceCollection services,

// Register notification handlers
.AddClasses(c => c.AssignableTo(typeof(INotificationHandler<>)))
.AsImplementedInterfaces()
.WithScopedLifetime()
.AsImplementedInterfaces()
.WithScopedLifetime()

// Register stream request handlers
.AddClasses(c => c.AssignableTo(typeof(IStreamRequestHandler<,>)))
Expand All @@ -72,7 +72,41 @@ public static IServiceCollection AddKSMediator(this IServiceCollection services,

// If you have default behaviors (e.g., logging), register them here
services.AddScoped(typeof(IStreamPipelineBehavior<,>), typeof(StreamLoggingBehavior<,>));

services.RegisterAllImplementationsOf<IRequestDecorator>(assemblies);

return services;
}

private static void RegisterAllImplementationsOf<TInterface>(this IServiceCollection services,
Assembly[] assemblies,
ServiceLifetime lifetime = ServiceLifetime.Scoped)
{
var interfaceType = typeof(TInterface);

foreach (var assembly in assemblies)
{
var implementations = assembly.DefinedTypes
.Where(type => type.IsClass && !type.IsAbstract && interfaceType.IsAssignableFrom(type))
.ToList();

foreach (var implementation in implementations)
{
switch (lifetime)
{
case ServiceLifetime.Transient:
services.AddTransient(interfaceType, implementation);
break;
case ServiceLifetime.Scoped:
services.AddScoped(interfaceType, implementation);
break;
case ServiceLifetime.Singleton:
services.AddSingleton(interfaceType, implementation);
break;
default:
throw new ArgumentException("Invalid service lifetime", nameof(lifetime));
}
}
}
}
}
6 changes: 6 additions & 0 deletions src/KSFramework/KSMessaging/IRequestDecorator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace KSFramework.KSMessaging;

public interface IRequestDecorator
{

}
13 changes: 13 additions & 0 deletions src/KSFramework/Pagination/OrderingRequestOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace KSFramework.Pagination;

public record OrderingRequestOptions
: PaginationRequestOptions
{
[property:JsonProperty("orderByPropertyName")]
public string OrderByPropertyName { get; set; } = "Id";

[property:JsonProperty("desc")]
public bool Desc { get; set; } = false;
}
12 changes: 12 additions & 0 deletions src/KSFramework/Pagination/PaginationRequestOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace KSFramework.Pagination;

public record PaginationRequestOptions
{
[property:JsonProperty("pageIndex")]
public int PageIndex { get; set; } = 1;

[property:JsonProperty("pageSize")]
public int PageSize { get; set; } = 20;
}
11 changes: 11 additions & 0 deletions src/KSFramework/Pagination/SearchRequestOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

using Newtonsoft.Json;

namespace KSFramework.Pagination;

public record SearchRequestOptions
: OrderingRequestOptions
{
[property:JsonProperty("searchTerm")]
public string SearchTerm { get; set; }
}
Loading