diff --git a/src/KSFramework/KSMessaging/Extensions/RegisterMediatorServices.cs b/src/KSFramework/KSMessaging/Extensions/RegisterMediatorServices.cs index 97ee026..92c6fca 100644 --- a/src/KSFramework/KSMessaging/Extensions/RegisterMediatorServices.cs +++ b/src/KSFramework/KSMessaging/Extensions/RegisterMediatorServices.cs @@ -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<,>))) @@ -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(assemblies); return services; } + + private static void RegisterAllImplementationsOf(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)); + } + } + } + } } \ No newline at end of file diff --git a/src/KSFramework/KSMessaging/IRequestDecorator.cs b/src/KSFramework/KSMessaging/IRequestDecorator.cs new file mode 100644 index 0000000..0d270fd --- /dev/null +++ b/src/KSFramework/KSMessaging/IRequestDecorator.cs @@ -0,0 +1,6 @@ +namespace KSFramework.KSMessaging; + +public interface IRequestDecorator +{ + +} \ No newline at end of file diff --git a/src/KSFramework/Pagination/OrderingRequestOptions.cs b/src/KSFramework/Pagination/OrderingRequestOptions.cs new file mode 100644 index 0000000..ce2060a --- /dev/null +++ b/src/KSFramework/Pagination/OrderingRequestOptions.cs @@ -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; +} \ No newline at end of file diff --git a/src/KSFramework/Pagination/PaginationRequestOptions.cs b/src/KSFramework/Pagination/PaginationRequestOptions.cs new file mode 100644 index 0000000..71fd264 --- /dev/null +++ b/src/KSFramework/Pagination/PaginationRequestOptions.cs @@ -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; +} \ No newline at end of file diff --git a/src/KSFramework/Pagination/SearchRequestOptions.cs b/src/KSFramework/Pagination/SearchRequestOptions.cs new file mode 100644 index 0000000..2284452 --- /dev/null +++ b/src/KSFramework/Pagination/SearchRequestOptions.cs @@ -0,0 +1,11 @@ + +using Newtonsoft.Json; + +namespace KSFramework.Pagination; + +public record SearchRequestOptions + : OrderingRequestOptions +{ + [property:JsonProperty("searchTerm")] + public string SearchTerm { get; set; } +} \ No newline at end of file