chore: cleanup of Masstransit library

This commit is contained in:
Timothy Schenk 2024-02-04 20:13:36 +01:00
parent e305ce49aa
commit c378ddba07
Signed by: rainote
SSH key fingerprint: SHA256:pnkNSDwpAnaip00xaZlVFHKKsS7T8UtOomMzvs0yITE
2 changed files with 4 additions and 6 deletions

View file

@ -7,7 +7,6 @@ using System.Reflection;
using DotNext.Collections.Generic; using DotNext.Collections.Generic;
using DotNext.Linq.Expressions; using DotNext.Linq.Expressions;
using DotNext.Metaprogramming; using DotNext.Metaprogramming;
using MassTransit.Internals;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualBasic.CompilerServices; using Microsoft.VisualBasic.CompilerServices;
@ -41,8 +40,8 @@ public class PacketDistributorService<T, S> : Microsoft.Extensions.Hosting.IHost
{ {
using var activity = this._activitySource.StartActivity(); using var activity = this._activitySource.StartActivity();
var packetsWithId = this._sourcesContainingPackets.SelectMany(a => a.GetTypes() var packetsWithId = this._sourcesContainingPackets.SelectMany(a => a.GetTypes()
.Where(type => .Where(type => type is { IsInterface: false, IsAbstract: false } &&
type.HasInterface(typeof(IIncomingPacket)) && type is { IsInterface: false, IsAbstract: false }) type.GetInterfaces().Contains(typeof(IIncomingPacket)))
.Select(type => new { Type = type, Attribute = type.GetCustomAttribute<PacketIdAttribute<T>>() }) .Select(type => new { Type = type, Attribute = type.GetCustomAttribute<PacketIdAttribute<T>>() })
.Where(item => item.Attribute is not null) .Where(item => item.Attribute is not null)
.ToDictionary(item => item.Attribute!.Code, item => item.Type)).ToDictionary(); .ToDictionary(item => item.Attribute!.Code, item => item.Type)).ToDictionary();
@ -66,8 +65,8 @@ public class PacketDistributorService<T, S> : Microsoft.Extensions.Hosting.IHost
PacketId = type PacketId = type
.GetInterfaces().First(t1 => .GetInterfaces().First(t1 =>
t1 is { IsGenericType: true } && t1.GetGenericTypeDefinition() == typeof(IPacketHandler<S>)) t1 is { IsGenericType: true } && t1.GetGenericTypeDefinition() == typeof(IPacketHandler<S>))
.GetGenericArguments().First(t => t.HasAttribute<PacketIdAttribute<T>>()) .GetGenericArguments().First(t => t.GetCustomAttributes<PacketIdAttribute<T>>().Any())
.GetAttribute<PacketIdAttribute<T>>().First().Code .GetCustomAttributes<PacketIdAttribute<T>>().First().Code
}) })
.ToDictionary( .ToDictionary(
x => x.PacketId, x => x.Type x => x.PacketId, x => x.Type

View file

@ -12,7 +12,6 @@
<PackageReference Include="DotNext.Threading" Version="5.0.1" /> <PackageReference Include="DotNext.Threading" Version="5.0.1" />
<PackageReference Include="DotNext.Unsafe" Version="5.0.1" /> <PackageReference Include="DotNext.Unsafe" Version="5.0.1" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" /> <PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="MassTransit" Version="8.1.3" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup> </ItemGroup>