Skip to content

Commit

Permalink
Update OfX- all to v3.1.1.
Browse files Browse the repository at this point in the history
Update add pipeline as custom lifetime-> Default is Scoped.
Change ReceivedPipelinesImpl -> Transient life-time!
  • Loading branch information
quyvu01 committed Jan 3, 2025
1 parent 405d4d4 commit c9389c9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/OfX.EntityFrameworkCore/OfX.EntityFrameworkCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<LangVersion>default</LangVersion>
<Version>3.1.0</Version>
<Version>3.1.1</Version>
<Authors>Quy Vu</Authors>
<PackageId>OfX-EFCore</PackageId>
<Description>OfX extension. Use EntityFramework as Data Querying</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/OfX.Grpc/OfX.Grpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<LangVersion>default</LangVersion>
<Version>3.1.0</Version>
<Version>3.1.1</Version>
<Authors>Quy Vu</Authors>
<PackageId>OfX-gRPC</PackageId>
<Description>OfX extension. Use gRPC as Data transporting</Description>
Expand Down
25 changes: 16 additions & 9 deletions src/OfX/ApplicationModels/ReceivedPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@ public sealed class ReceivedPipeline(IServiceCollection serviceCollection)
{
private static readonly Type interfaceReceivedPipeline = typeof(IReceivedPipelineBehavior<>);

public ReceivedPipeline OfType<TReceivedPipeline>()
public ReceivedPipeline OfType<TReceivedPipeline>(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;
}
}
2 changes: 1 addition & 1 deletion src/OfX/Extensions/OfXExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static OfXRegister AddOfX(this IServiceCollection serviceCollection, Acti
serviceCollection.AddScoped<IDataMappableService>(sp =>
new DataMappableService(sp, newOfRegister.AttributesRegister));

serviceCollection.AddScoped(typeof(ReceivedPipelinesImpl<,>));
serviceCollection.AddTransient(typeof(ReceivedPipelinesImpl<,>));

return newOfRegister;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OfX/OfX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<LangVersion>default</LangVersion>
<Version>3.1.0</Version>
<Version>3.1.1</Version>
<Authors>Quy Vu</Authors>
<PackageId>OfX</PackageId>
<Description>The high performance and easiest way to play with microservices for .NET</Description>
Expand Down

0 comments on commit c9389c9

Please sign in to comment.