From c9389c9a6761e8f2bd45ed50b9a9e334b7606da2 Mon Sep 17 00:00:00 2001 From: quyvu Date: Fri, 3 Jan 2025 13:32:37 +0700 Subject: [PATCH] Update OfX- all to v3.1.1. Update add pipeline as custom lifetime-> Default is Scoped. Change ReceivedPipelinesImpl -> Transient life-time! --- .../OfX.EntityFrameworkCore.csproj | 2 +- src/OfX.Grpc/OfX.Grpc.csproj | 2 +- src/OfX/ApplicationModels/ReceivedPipeline.cs | 25 ++++++++++++------- src/OfX/Extensions/OfXExtensions.cs | 2 +- src/OfX/OfX.csproj | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/OfX.EntityFrameworkCore/OfX.EntityFrameworkCore.csproj b/src/OfX.EntityFrameworkCore/OfX.EntityFrameworkCore.csproj index 4c49708..66ca3e0 100644 --- a/src/OfX.EntityFrameworkCore/OfX.EntityFrameworkCore.csproj +++ b/src/OfX.EntityFrameworkCore/OfX.EntityFrameworkCore.csproj @@ -4,7 +4,7 @@ enable net9.0;net8.0 default - 3.1.0 + 3.1.1 Quy Vu OfX-EFCore OfX extension. Use EntityFramework as Data Querying diff --git a/src/OfX.Grpc/OfX.Grpc.csproj b/src/OfX.Grpc/OfX.Grpc.csproj index dfb49f3..2872c5e 100644 --- a/src/OfX.Grpc/OfX.Grpc.csproj +++ b/src/OfX.Grpc/OfX.Grpc.csproj @@ -4,7 +4,7 @@ enable net9.0;net8.0 default - 3.1.0 + 3.1.1 Quy Vu OfX-gRPC OfX extension. Use gRPC as Data transporting diff --git a/src/OfX/ApplicationModels/ReceivedPipeline.cs b/src/OfX/ApplicationModels/ReceivedPipeline.cs index 999cce3..793c095 100644 --- a/src/OfX/ApplicationModels/ReceivedPipeline.cs +++ b/src/OfX/ApplicationModels/ReceivedPipeline.cs @@ -8,29 +8,36 @@ public sealed class ReceivedPipeline(IServiceCollection serviceCollection) { private static readonly Type interfaceReceivedPipeline = typeof(IReceivedPipelineBehavior<>); - public ReceivedPipeline OfType() + public ReceivedPipeline OfType(ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { OfType(typeof(TReceivedPipeline)); return this; } // Hmmm, this one is temporary!. I think should test more case! - public ReceivedPipeline OfType(Type pipelineType) + public ReceivedPipeline OfType(Type pipelineType, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { - var signatureInterfaceType = pipelineType.GetInterfaces() - .FirstOrDefault(a => a.IsGenericType && a.GetGenericTypeDefinition() == interfaceReceivedPipeline); - if (signatureInterfaceType is null) + var signatureInterfaceTypes = pipelineType.GetInterfaces() + .Where(a => a.IsGenericType && a.GetGenericTypeDefinition() == interfaceReceivedPipeline) + .ToList(); + + if (signatureInterfaceTypes is not { Count: > 0 }) throw new OfXException.PipelineIsNotReceivedPipelineBehavior(pipelineType); if (pipelineType.IsGenericType) { - var isContainsGenericParameters = pipelineType.ContainsGenericParameters; - if (isContainsGenericParameters) + if (pipelineType.ContainsGenericParameters) { - serviceCollection.AddScoped(interfaceReceivedPipeline, pipelineType); + var serviceDescriptor = new ServiceDescriptor(interfaceReceivedPipeline, pipelineType, serviceLifetime); + serviceCollection.Add(serviceDescriptor); return this; } } - serviceCollection.AddScoped(signatureInterfaceType, pipelineType); + + signatureInterfaceTypes.ForEach(serviceType => + { + var serviceDescriptor = new ServiceDescriptor(serviceType, pipelineType, serviceLifetime); + serviceCollection.Add(serviceDescriptor); + }); return this; } } \ No newline at end of file diff --git a/src/OfX/Extensions/OfXExtensions.cs b/src/OfX/Extensions/OfXExtensions.cs index 679c6d5..84da98d 100644 --- a/src/OfX/Extensions/OfXExtensions.cs +++ b/src/OfX/Extensions/OfXExtensions.cs @@ -63,7 +63,7 @@ public static OfXRegister AddOfX(this IServiceCollection serviceCollection, Acti serviceCollection.AddScoped(sp => new DataMappableService(sp, newOfRegister.AttributesRegister)); - serviceCollection.AddScoped(typeof(ReceivedPipelinesImpl<,>)); + serviceCollection.AddTransient(typeof(ReceivedPipelinesImpl<,>)); return newOfRegister; } diff --git a/src/OfX/OfX.csproj b/src/OfX/OfX.csproj index 8324814..51bbda8 100644 --- a/src/OfX/OfX.csproj +++ b/src/OfX/OfX.csproj @@ -4,7 +4,7 @@ enable net9.0;net8.0 default - 3.1.0 + 3.1.1 Quy Vu OfX The high performance and easiest way to play with microservices for .NET