com.wallstop-studios.dxmessaging 2.2.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -67
- package/CHANGELOG.md.meta +7 -7
- package/Editor/Analyzers/BaseCallIlInspector.cs +277 -0
- package/Editor/Analyzers/BaseCallIlInspector.cs.meta +11 -0
- package/Editor/Analyzers/BaseCallLogMessageParser.cs +295 -0
- package/Editor/Analyzers/BaseCallLogMessageParser.cs.meta +11 -0
- package/Editor/Analyzers/BaseCallReportAggregator.cs +308 -0
- package/Editor/Analyzers/BaseCallReportAggregator.cs.meta +11 -0
- package/Editor/Analyzers/BaseCallTypeScanner.cs +110 -0
- package/Editor/Analyzers/BaseCallTypeScanner.cs.meta +11 -0
- package/Editor/Analyzers/BaseCallTypeScannerCore.cs +562 -0
- package/Editor/Analyzers/BaseCallTypeScannerCore.cs.meta +11 -0
- package/Editor/Analyzers/DxMessagingConsoleHarvester.cs +1122 -0
- package/Editor/Analyzers/DxMessagingConsoleHarvester.cs.meta +11 -0
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +44 -44
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +44 -44
- package/Editor/Analyzers/System.Collections.Immutable.dll.meta +44 -44
- package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +44 -44
- package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll.meta +44 -44
- package/Editor/Analyzers/WallstopStudios.DxMessaging.Analyzer.dll +0 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.Analyzer.dll.meta +33 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +72 -72
- package/Editor/Analyzers.meta +8 -8
- package/Editor/AssemblyInfo.cs.meta +3 -3
- package/Editor/CustomEditors/MessageAwareComponentFallbackEditor.cs +81 -0
- package/Editor/CustomEditors/MessageAwareComponentFallbackEditor.cs.meta +11 -0
- package/Editor/CustomEditors/MessageAwareComponentInspectorOverlay.cs +420 -0
- package/Editor/CustomEditors/MessageAwareComponentInspectorOverlay.cs.meta +11 -0
- package/Editor/CustomEditors/MessagingComponentEditor.cs +1 -1
- package/Editor/CustomEditors/MessagingComponentEditor.cs.meta +2 -2
- package/Editor/CustomEditors.meta +2 -2
- package/Editor/DxMessagingEditorInitializer.cs.meta +2 -2
- package/Editor/DxMessagingMenu.cs.meta +11 -11
- package/Editor/DxMessagingSceneBuildProcessor.cs.meta +11 -11
- package/Editor/Settings/DxMessagingBaseCallIgnoreSync.cs +190 -0
- package/Editor/Settings/DxMessagingBaseCallIgnoreSync.cs.meta +11 -0
- package/Editor/Settings/DxMessagingSettings.cs +189 -0
- package/Editor/Settings/DxMessagingSettings.cs.meta +2 -2
- package/Editor/Settings/DxMessagingSettingsProvider.cs +50 -33
- package/Editor/Settings/DxMessagingSettingsProvider.cs.meta +2 -2
- package/Editor/Settings.meta +2 -2
- package/Editor/SetupCscRsp.cs +209 -8
- package/Editor/SetupCscRsp.cs.meta +2 -2
- package/Editor/Testing/MessagingComponentEditorHarness.cs +1 -1
- package/Editor/Testing/MessagingComponentEditorHarness.cs.meta +3 -3
- package/Editor/Testing.meta +3 -3
- package/Editor/WallstopStudios.DxMessaging.Editor.asmdef +14 -14
- package/Editor/WallstopStudios.DxMessaging.Editor.asmdef.meta +7 -7
- package/Editor.meta +8 -8
- package/LICENSE.md +9 -9
- package/LICENSE.md.meta +7 -7
- package/README.md +941 -900
- package/README.md.meta +7 -7
- package/Runtime/AssemblyInfo.cs +4 -0
- package/Runtime/AssemblyInfo.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxAutoConstructorAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxIgnoreMissingBaseCallAttribute.cs +26 -0
- package/Runtime/Core/Attributes/DxIgnoreMissingBaseCallAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes.meta +2 -2
- package/Runtime/Core/Configuration/DxMessagingRuntimeSettings.cs +195 -0
- package/Runtime/Core/Configuration/DxMessagingRuntimeSettings.cs.meta +11 -0
- package/Runtime/Core/Configuration/DxMessagingRuntimeSettingsProvider.cs +179 -0
- package/Runtime/Core/Configuration/DxMessagingRuntimeSettingsProvider.cs.meta +11 -0
- package/Runtime/Core/Configuration.meta +9 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +2 -2
- package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +2 -2
- package/Runtime/Core/DataStructure.meta +2 -2
- package/Runtime/Core/Diagnostics/MessageEmissionData.cs.meta +2 -2
- package/Runtime/Core/Diagnostics/MessageRegistrationData.cs.meta +2 -2
- package/Runtime/Core/Diagnostics/MessageRegistrationType.cs.meta +2 -2
- package/Runtime/Core/Diagnostics.meta +2 -2
- package/Runtime/Core/DxMessagingStaticState.cs +19 -0
- package/Runtime/Core/DxMessagingStaticState.cs.meta +11 -11
- package/Runtime/Core/Extensions/EnumExtensions.cs.meta +2 -2
- package/Runtime/Core/Extensions/IListExtensions.cs.meta +2 -2
- package/Runtime/Core/Extensions/MessageBusExtensions.cs.meta +12 -12
- package/Runtime/Core/Extensions/MessageExtensions.cs.meta +11 -11
- package/Runtime/Core/Extensions.meta +8 -8
- package/Runtime/Core/Helper/MessageCache.cs +32 -0
- package/Runtime/Core/Helper/MessageCache.cs.meta +2 -2
- package/Runtime/Core/Helper/MessageHelperIndexer.cs.meta +2 -2
- package/Runtime/Core/Helper.meta +2 -2
- package/Runtime/Core/IMessage.cs +3 -3
- package/Runtime/Core/IMessage.cs.meta +11 -11
- package/Runtime/Core/InstanceId.cs.meta +11 -11
- package/Runtime/Core/Internal/TypedDispatchLinkIndex.cs +51 -0
- package/Runtime/Core/Internal/TypedDispatchLinkIndex.cs.meta +11 -0
- package/Runtime/Core/Internal/TypedGlobalSlotIndex.cs +38 -0
- package/Runtime/Core/Internal/TypedGlobalSlotIndex.cs.meta +11 -0
- package/Runtime/Core/Internal/TypedSlotIndex.cs +81 -0
- package/Runtime/Core/Internal/TypedSlotIndex.cs.meta +11 -0
- package/Runtime/Core/Internal/TypedSlots.cs +613 -0
- package/Runtime/Core/Internal/TypedSlots.cs.meta +11 -0
- package/Runtime/Core/Internal.meta +9 -0
- package/Runtime/Core/MessageBus/DiagnosticsTarget.cs.meta +11 -11
- package/Runtime/Core/MessageBus/GlobalMessageBusProvider.cs.meta +11 -11
- package/Runtime/Core/MessageBus/IMessageBus.cs +177 -3
- package/Runtime/Core/MessageBus/IMessageBus.cs.meta +11 -11
- package/Runtime/Core/MessageBus/IMessageBusProvider.cs.meta +11 -11
- package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs.meta +11 -11
- package/Runtime/Core/MessageBus/Internal/BusContextIndex.cs +16 -0
- package/Runtime/Core/MessageBus/Internal/BusContextIndex.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/BusSinkIndex.cs +40 -0
- package/Runtime/Core/MessageBus/Internal/BusSinkIndex.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/BusSlots.cs +718 -0
- package/Runtime/Core/MessageBus/Internal/BusSlots.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/DispatchKind.cs +38 -0
- package/Runtime/Core/MessageBus/Internal/DispatchKind.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/DispatchPhase.cs +20 -0
- package/Runtime/Core/MessageBus/Internal/DispatchPhase.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/DispatchVariant.cs +28 -0
- package/Runtime/Core/MessageBus/Internal/DispatchVariant.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/IEvictableSlot.cs +48 -0
- package/Runtime/Core/MessageBus/Internal/IEvictableSlot.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/ISweepable.cs +15 -0
- package/Runtime/Core/MessageBus/Internal/ISweepable.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/RegistrationMethodAxes.cs +222 -0
- package/Runtime/Core/MessageBus/Internal/RegistrationMethodAxes.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal/SlotKey.cs +192 -0
- package/Runtime/Core/MessageBus/Internal/SlotKey.cs.meta +11 -0
- package/Runtime/Core/MessageBus/Internal.meta +9 -0
- package/Runtime/Core/MessageBus/MessageBus.cs +2651 -500
- package/Runtime/Core/MessageBus/MessageBus.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessageBusRebindMode.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessagingRegistration.cs.meta +11 -11
- package/Runtime/Core/MessageBus/RegistrationLog.cs.meta +11 -11
- package/Runtime/Core/MessageBus.meta +8 -8
- package/Runtime/Core/MessageHandler.cs +2019 -542
- package/Runtime/Core/MessageHandler.cs.meta +11 -11
- package/Runtime/Core/MessageRegistrationHandle.cs.meta +11 -11
- package/Runtime/Core/MessageRegistrationToken.cs +7 -0
- package/Runtime/Core/MessageRegistrationToken.cs.meta +11 -11
- package/Runtime/Core/Messages/GlobalStringMessage.cs.meta +2 -2
- package/Runtime/Core/Messages/IBroadcastMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/ITargetedMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/IUntargetedMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/ReflexiveMessage.cs.meta +2 -2
- package/Runtime/Core/Messages/SourcedStringMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/StringMessage.cs.meta +2 -2
- package/Runtime/Core/Messages.meta +8 -8
- package/Runtime/Core/MessagingDebug.cs.meta +11 -11
- package/Runtime/Core/Pooling/CollectionPool.cs +266 -0
- package/Runtime/Core/Pooling/CollectionPool.cs.meta +11 -0
- package/Runtime/Core/Pooling/CollectionPoolDiagnostics.cs +30 -0
- package/Runtime/Core/Pooling/CollectionPoolDiagnostics.cs.meta +11 -0
- package/Runtime/Core/Pooling/DxPools.cs +157 -0
- package/Runtime/Core/Pooling/DxPools.cs.meta +11 -0
- package/Runtime/Core/Pooling/EvictionPlayerLoopHook.cs +106 -0
- package/Runtime/Core/Pooling/EvictionPlayerLoopHook.cs.meta +11 -0
- package/Runtime/Core/Pooling/IDxMessagingClock.cs +18 -0
- package/Runtime/Core/Pooling/IDxMessagingClock.cs.meta +11 -0
- package/Runtime/Core/Pooling/PoolDiagnosticsSnapshot.cs +55 -0
- package/Runtime/Core/Pooling/PoolDiagnosticsSnapshot.cs.meta +11 -0
- package/Runtime/Core/Pooling/StopwatchClock.cs +27 -0
- package/Runtime/Core/Pooling/StopwatchClock.cs.meta +11 -0
- package/Runtime/Core/Pooling/UnityRealtimeClock.cs +31 -0
- package/Runtime/Core/Pooling/UnityRealtimeClock.cs.meta +11 -0
- package/Runtime/Core/Pooling.meta +9 -0
- package/Runtime/Core.meta +8 -8
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs.meta +12 -12
- package/Runtime/Unity/DxMessagingRuntimeInitializer.cs.meta +11 -11
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs.meta +12 -12
- package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs.meta +2 -2
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +73 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs.meta +11 -11
- package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef +20 -20
- package/Runtime/Unity/Integrations/Reflex/WallstopStudios.DxMessaging.Reflex.asmdef.meta +7 -7
- package/Runtime/Unity/Integrations/Reflex.meta +8 -8
- package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs.meta +2 -2
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +109 -1
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs.meta +11 -11
- package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef +30 -30
- package/Runtime/Unity/Integrations/VContainer/WallstopStudios.DxMessaging.VContainer.asmdef.meta +7 -7
- package/Runtime/Unity/Integrations/VContainer.meta +8 -8
- package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs.meta +2 -2
- package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef +30 -30
- package/Runtime/Unity/Integrations/Zenject/WallstopStudios.DxMessaging.Zenject.asmdef.meta +7 -7
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +79 -1
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs.meta +11 -11
- package/Runtime/Unity/Integrations/Zenject.meta +8 -8
- package/Runtime/Unity/Integrations.meta +8 -8
- package/Runtime/Unity/MessageAwareComponent.cs +29 -0
- package/Runtime/Unity/MessageAwareComponent.cs.meta +11 -11
- package/Runtime/Unity/MessageBusProviderHandle.cs.meta +12 -12
- package/Runtime/Unity/MessagingComponent.cs.meta +11 -11
- package/Runtime/Unity/MessagingComponentInstaller.cs.meta +12 -12
- package/Runtime/Unity/ScriptableMessageBusProvider.cs.meta +12 -12
- package/Runtime/Unity.meta +8 -8
- package/Runtime/WallstopStudios.DxMessaging.asmdef +14 -14
- package/Runtime/WallstopStudios.DxMessaging.asmdef.meta +7 -7
- package/Runtime.meta +8 -8
- package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab +98 -98
- package/Samples~/DI/Prefabs/MessagingInstallerSample.prefab.meta +7 -7
- package/Samples~/DI/Prefabs.meta +8 -8
- package/Samples~/DI/Providers/GlobalMessageBusProvider.asset +14 -14
- package/Samples~/DI/Providers/GlobalMessageBusProvider.asset.meta +8 -8
- package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset +14 -14
- package/Samples~/DI/Providers/InitialGlobalMessageBusProvider.asset.meta +8 -8
- package/Samples~/DI/Providers.meta +8 -8
- package/Samples~/DI/README.md +51 -51
- package/Samples~/DI/README.md.meta +7 -7
- package/Samples~/DI/Reflex/SampleInstaller.cs +7 -0
- package/Samples~/DI/Reflex/SampleInstaller.cs.meta +11 -11
- package/Samples~/DI/Reflex.meta +8 -8
- package/Samples~/DI/VContainer/SampleLifetimeScope.cs +6 -1
- package/Samples~/DI/VContainer/SampleLifetimeScope.cs.meta +11 -11
- package/Samples~/DI/VContainer.meta +8 -8
- package/Samples~/DI/Zenject/SampleInstaller.cs +8 -0
- package/Samples~/DI/Zenject/SampleInstaller.cs.meta +11 -11
- package/Samples~/DI/Zenject.meta +8 -8
- package/Samples~/DI.meta +8 -8
- package/Samples~/Mini Combat/Boot.cs.meta +11 -11
- package/Samples~/Mini Combat/Enemy.cs.meta +11 -11
- package/Samples~/Mini Combat/Messages.cs.meta +11 -11
- package/Samples~/Mini Combat/Player.cs.meta +11 -11
- package/Samples~/Mini Combat/README.md +324 -323
- package/Samples~/Mini Combat/README.md.meta +7 -7
- package/Samples~/Mini Combat/UIOverlay.cs.meta +11 -11
- package/Samples~/Mini Combat/Walkthrough.md +430 -430
- package/Samples~/Mini Combat/Walkthrough.md.meta +7 -7
- package/Samples~/Mini Combat/WallstopStudios.DxMessaging.MiniCombat.Sample.asmdef +13 -13
- package/Samples~/Mini Combat/WallstopStudios.DxMessaging.MiniCombat.Sample.asmdef.meta +7 -7
- package/Samples~/Mini Combat.meta +8 -8
- package/Samples~/UI Buttons + Inspector/DiagnosticsEnabler.cs.meta +11 -11
- package/Samples~/UI Buttons + Inspector/Messages.cs.meta +11 -11
- package/Samples~/UI Buttons + Inspector/MessagingObserver.cs.meta +11 -11
- package/Samples~/UI Buttons + Inspector/README.md +210 -209
- package/Samples~/UI Buttons + Inspector/README.md.meta +7 -7
- package/Samples~/UI Buttons + Inspector/UIButtonEmitter.cs.meta +11 -11
- package/Samples~/UI Buttons + Inspector/WallstopStudios.DxMessaging.UIButtons.Sample.asmdef +13 -13
- package/Samples~/UI Buttons + Inspector/WallstopStudios.DxMessaging.UIButtons.Sample.asmdef.meta +7 -7
- package/Samples~/UI Buttons + Inspector.meta +8 -8
- package/SourceGenerators/Directory.Build.props.meta +7 -7
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs.meta +11 -11
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj.meta +7 -7
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.meta +8 -8
- package/SourceGenerators.meta +8 -8
- package/Third Party Notices.md +3 -3
- package/Third Party Notices.md.meta +7 -7
- package/package.json +115 -92
- package/package.json.meta +7 -7
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Pooling
|
|
2
|
+
{
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using DxMessaging.Core.Internal;
|
|
5
|
+
#if UNITY_2021_3_OR_NEWER
|
|
6
|
+
using Configuration;
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// Static, single-threaded pool registry shared by the bus and handler
|
|
11
|
+
/// subsystems. Instantiated lazily on first use; reconfigured by
|
|
12
|
+
/// <see cref="Configure"/> when the runtime settings asset changes.
|
|
13
|
+
/// </summary>
|
|
14
|
+
/// <remarks>
|
|
15
|
+
/// Each pool returns the per-entry recycle action that clears the entry
|
|
16
|
+
/// before re-use, so callers do not need to remember to <c>Clear()</c>
|
|
17
|
+
/// before <c>Return</c>. <c>OnEvicted</c> currently does nothing -- entries
|
|
18
|
+
/// are dropped on cap overflow and the GC reclaims them.
|
|
19
|
+
/// </remarks>
|
|
20
|
+
internal static class DxPools
|
|
21
|
+
{
|
|
22
|
+
// Mirrors DxMessagingRuntimeSettings.DefaultBufferMaxDistinctEntries; updated by Configure().
|
|
23
|
+
// Kept as a local constant so DxPools' field initializers don't depend on Unity types.
|
|
24
|
+
private const int DefaultMaxRetained = 512;
|
|
25
|
+
|
|
26
|
+
internal static readonly CollectionPool<Dictionary<InstanceId, object>> InstanceIdDicts =
|
|
27
|
+
new(
|
|
28
|
+
maxRetained: DefaultMaxRetained,
|
|
29
|
+
useLru: true,
|
|
30
|
+
factory: () => new Dictionary<InstanceId, object>(),
|
|
31
|
+
onRecycled: dict => dict.Clear()
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
internal static readonly CollectionPool<List<InstanceId>> InstanceIdLists = new(
|
|
35
|
+
maxRetained: DefaultMaxRetained,
|
|
36
|
+
useLru: true,
|
|
37
|
+
factory: () => new List<InstanceId>(),
|
|
38
|
+
onRecycled: list => list.Clear()
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
internal static readonly CollectionPool<HashSet<InstanceId>> InstanceIdSets = new(
|
|
42
|
+
maxRetained: DefaultMaxRetained,
|
|
43
|
+
useLru: true,
|
|
44
|
+
factory: () => new HashSet<InstanceId>(),
|
|
45
|
+
onRecycled: set => set.Clear()
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
internal static readonly CollectionPool<List<object>> ObjectLists = new(
|
|
49
|
+
maxRetained: DefaultMaxRetained,
|
|
50
|
+
useLru: true,
|
|
51
|
+
factory: () => new List<object>(),
|
|
52
|
+
onRecycled: list => list.Clear()
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
internal static readonly CollectionPool<Stack<object>> ObjectStacks = new(
|
|
56
|
+
maxRetained: DefaultMaxRetained,
|
|
57
|
+
useLru: true,
|
|
58
|
+
factory: () => new Stack<object>(),
|
|
59
|
+
onRecycled: stack => stack.Clear()
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
internal static readonly CollectionPool<HashSet<int>> IntSets = new(
|
|
63
|
+
maxRetained: DefaultMaxRetained,
|
|
64
|
+
useLru: true,
|
|
65
|
+
factory: () => new HashSet<int>(),
|
|
66
|
+
onRecycled: set => set.Clear()
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
internal static readonly CollectionPool<
|
|
70
|
+
Dictionary<InstanceId, Dictionary<int, IHandlerActionCache>>
|
|
71
|
+
> TypedHandlerContextDicts = new(
|
|
72
|
+
maxRetained: DefaultMaxRetained,
|
|
73
|
+
useLru: true,
|
|
74
|
+
factory: () => new Dictionary<InstanceId, Dictionary<int, IHandlerActionCache>>(),
|
|
75
|
+
onRecycled: dict => dict.Clear()
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
internal static readonly CollectionPool<
|
|
79
|
+
Dictionary<int, IHandlerActionCache>
|
|
80
|
+
> TypedHandlerPriorityDicts = new(
|
|
81
|
+
maxRetained: DefaultMaxRetained,
|
|
82
|
+
useLru: true,
|
|
83
|
+
factory: () => new Dictionary<int, IHandlerActionCache>(),
|
|
84
|
+
onRecycled: dict => dict.Clear()
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
/// <summary>
|
|
88
|
+
/// Trim every pool. <paramref name="force"/> drains pools to zero;
|
|
89
|
+
/// otherwise each pool is trimmed to its current cap (a no-op unless the
|
|
90
|
+
/// cap was lowered). Returns total evicted count.
|
|
91
|
+
/// </summary>
|
|
92
|
+
internal static int TrimAll(bool force)
|
|
93
|
+
{
|
|
94
|
+
int evicted = 0;
|
|
95
|
+
evicted += InstanceIdDicts.Trim(force ? 0 : InstanceIdDicts.MaxRetained);
|
|
96
|
+
evicted += InstanceIdLists.Trim(force ? 0 : InstanceIdLists.MaxRetained);
|
|
97
|
+
evicted += InstanceIdSets.Trim(force ? 0 : InstanceIdSets.MaxRetained);
|
|
98
|
+
evicted += ObjectLists.Trim(force ? 0 : ObjectLists.MaxRetained);
|
|
99
|
+
evicted += ObjectStacks.Trim(force ? 0 : ObjectStacks.MaxRetained);
|
|
100
|
+
evicted += IntSets.Trim(force ? 0 : IntSets.MaxRetained);
|
|
101
|
+
evicted += TypedHandlerContextDicts.Trim(
|
|
102
|
+
force ? 0 : TypedHandlerContextDicts.MaxRetained
|
|
103
|
+
);
|
|
104
|
+
evicted += TypedHandlerPriorityDicts.Trim(
|
|
105
|
+
force ? 0 : TypedHandlerPriorityDicts.MaxRetained
|
|
106
|
+
);
|
|
107
|
+
return evicted;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#if UNITY_2021_3_OR_NEWER
|
|
111
|
+
/// <summary>
|
|
112
|
+
/// Re-apply caps from the supplied settings. Lowering a cap immediately
|
|
113
|
+
/// trims; raising a cap takes effect on subsequent returns.
|
|
114
|
+
/// </summary>
|
|
115
|
+
internal static void Configure(DxMessagingRuntimeSettings settings)
|
|
116
|
+
{
|
|
117
|
+
if (settings == null)
|
|
118
|
+
{
|
|
119
|
+
throw new System.ArgumentNullException(nameof(settings));
|
|
120
|
+
}
|
|
121
|
+
int cap = settings.BufferMaxDistinctEntries;
|
|
122
|
+
bool useLru = settings.BufferUseLruEviction;
|
|
123
|
+
InstanceIdDicts.UseLru = useLru;
|
|
124
|
+
InstanceIdLists.UseLru = useLru;
|
|
125
|
+
InstanceIdSets.UseLru = useLru;
|
|
126
|
+
ObjectLists.UseLru = useLru;
|
|
127
|
+
ObjectStacks.UseLru = useLru;
|
|
128
|
+
IntSets.UseLru = useLru;
|
|
129
|
+
TypedHandlerContextDicts.UseLru = useLru;
|
|
130
|
+
TypedHandlerPriorityDicts.UseLru = useLru;
|
|
131
|
+
InstanceIdDicts.MaxRetained = cap;
|
|
132
|
+
InstanceIdLists.MaxRetained = cap;
|
|
133
|
+
InstanceIdSets.MaxRetained = cap;
|
|
134
|
+
ObjectLists.MaxRetained = cap;
|
|
135
|
+
ObjectStacks.MaxRetained = cap;
|
|
136
|
+
IntSets.MaxRetained = cap;
|
|
137
|
+
TypedHandlerContextDicts.MaxRetained = cap;
|
|
138
|
+
TypedHandlerPriorityDicts.MaxRetained = cap;
|
|
139
|
+
}
|
|
140
|
+
#endif
|
|
141
|
+
|
|
142
|
+
/// <summary>Aggregate snapshot of every pool's diagnostics.</summary>
|
|
143
|
+
internal static PoolDiagnosticsSnapshot DescribeAll()
|
|
144
|
+
{
|
|
145
|
+
return new PoolDiagnosticsSnapshot(
|
|
146
|
+
InstanceIdDicts.Snapshot(),
|
|
147
|
+
InstanceIdLists.Snapshot(),
|
|
148
|
+
InstanceIdSets.Snapshot(),
|
|
149
|
+
ObjectLists.Snapshot(),
|
|
150
|
+
ObjectStacks.Snapshot(),
|
|
151
|
+
IntSets.Snapshot(),
|
|
152
|
+
TypedHandlerContextDicts.Snapshot(),
|
|
153
|
+
TypedHandlerPriorityDicts.Snapshot()
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#if UNITY_2021_3_OR_NEWER
|
|
2
|
+
namespace DxMessaging.Core.Pooling
|
|
3
|
+
{
|
|
4
|
+
using System;
|
|
5
|
+
using MessageBus;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
using UnityEngine.LowLevel;
|
|
8
|
+
using UnityEngine.PlayerLoop;
|
|
9
|
+
|
|
10
|
+
/// <summary>
|
|
11
|
+
/// Unity PlayerLoop bridge that gives idle eviction a cadence even when no
|
|
12
|
+
/// messages are emitted.
|
|
13
|
+
/// </summary>
|
|
14
|
+
internal static class EvictionPlayerLoopHook
|
|
15
|
+
{
|
|
16
|
+
private static readonly Type HookType = typeof(EvictionPlayerLoopHook);
|
|
17
|
+
|
|
18
|
+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
|
19
|
+
private static void Install()
|
|
20
|
+
{
|
|
21
|
+
PlayerLoopSystem root = PlayerLoop.GetCurrentPlayerLoop();
|
|
22
|
+
if (InstallInto(ref root))
|
|
23
|
+
{
|
|
24
|
+
PlayerLoop.SetPlayerLoop(root);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
internal static bool InstallInto(ref PlayerLoopSystem root)
|
|
29
|
+
{
|
|
30
|
+
if (ContainsHook(root))
|
|
31
|
+
{
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
PlayerLoopSystem hook = new PlayerLoopSystem
|
|
36
|
+
{
|
|
37
|
+
type = HookType,
|
|
38
|
+
updateDelegate = SweepIdleBuses,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return InsertUnder<Update>(ref root, hook);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private static void SweepIdleBuses()
|
|
45
|
+
{
|
|
46
|
+
MessageBus.SweepIdleBusesFromPlayerLoop();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
internal static bool ContainsHook(PlayerLoopSystem system)
|
|
50
|
+
{
|
|
51
|
+
if (system.type == HookType)
|
|
52
|
+
{
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
PlayerLoopSystem[] subsystems = system.subSystemList;
|
|
57
|
+
if (subsystems == null)
|
|
58
|
+
{
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (int i = 0; i < subsystems.Length; ++i)
|
|
63
|
+
{
|
|
64
|
+
if (ContainsHook(subsystems[i]))
|
|
65
|
+
{
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private static bool InsertUnder<TTarget>(ref PlayerLoopSystem system, PlayerLoopSystem hook)
|
|
74
|
+
{
|
|
75
|
+
if (system.type == typeof(TTarget))
|
|
76
|
+
{
|
|
77
|
+
PlayerLoopSystem[] oldList =
|
|
78
|
+
system.subSystemList ?? Array.Empty<PlayerLoopSystem>();
|
|
79
|
+
PlayerLoopSystem[] newList = new PlayerLoopSystem[oldList.Length + 1];
|
|
80
|
+
Array.Copy(oldList, newList, oldList.Length);
|
|
81
|
+
newList[oldList.Length] = hook;
|
|
82
|
+
system.subSystemList = newList;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
PlayerLoopSystem[] subsystems = system.subSystemList;
|
|
87
|
+
if (subsystems == null)
|
|
88
|
+
{
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (int i = 0; i < subsystems.Length; ++i)
|
|
93
|
+
{
|
|
94
|
+
PlayerLoopSystem child = subsystems[i];
|
|
95
|
+
if (InsertUnder<TTarget>(ref child, hook))
|
|
96
|
+
{
|
|
97
|
+
subsystems[i] = child;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
#endif
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Pooling
|
|
2
|
+
{
|
|
3
|
+
/// <summary>
|
|
4
|
+
/// Abstraction over a monotonic wall-clock used by the eviction sweeper to
|
|
5
|
+
/// decide whether enough time has elapsed since the last sweep. Implementations
|
|
6
|
+
/// must be cheap (single field read or call) because sampled idle-sweep gates
|
|
7
|
+
/// sit on the emit path.
|
|
8
|
+
/// </summary>
|
|
9
|
+
public interface IDxMessagingClock
|
|
10
|
+
{
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Current time in seconds. Must be non-decreasing within a single
|
|
13
|
+
/// AppDomain. Implementations may have frame-grained or millisecond-grained
|
|
14
|
+
/// resolution; the eviction sweeper tolerates either.
|
|
15
|
+
/// </summary>
|
|
16
|
+
double NowSeconds { get; }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Pooling
|
|
2
|
+
{
|
|
3
|
+
/// <summary>
|
|
4
|
+
/// Aggregate snapshot of every <see cref="DxPools"/> pool. Returned by
|
|
5
|
+
/// <see cref="DxPools.DescribeAll"/>. Pool names are stable, human-readable
|
|
6
|
+
/// strings safe to log.
|
|
7
|
+
/// </summary>
|
|
8
|
+
internal readonly struct PoolDiagnosticsSnapshot
|
|
9
|
+
{
|
|
10
|
+
/// <summary><c>Dictionary<InstanceId, object></c> pool diagnostics.</summary>
|
|
11
|
+
public readonly CollectionPoolDiagnostics InstanceIdDicts;
|
|
12
|
+
|
|
13
|
+
/// <summary><c>List<InstanceId></c> pool diagnostics.</summary>
|
|
14
|
+
public readonly CollectionPoolDiagnostics InstanceIdLists;
|
|
15
|
+
|
|
16
|
+
/// <summary><c>HashSet<InstanceId></c> pool diagnostics.</summary>
|
|
17
|
+
public readonly CollectionPoolDiagnostics InstanceIdSets;
|
|
18
|
+
|
|
19
|
+
/// <summary><c>List<object></c> pool diagnostics.</summary>
|
|
20
|
+
public readonly CollectionPoolDiagnostics ObjectLists;
|
|
21
|
+
|
|
22
|
+
/// <summary><c>Stack<object></c> pool diagnostics.</summary>
|
|
23
|
+
public readonly CollectionPoolDiagnostics ObjectStacks;
|
|
24
|
+
|
|
25
|
+
/// <summary><c>HashSet<int></c> pool diagnostics.</summary>
|
|
26
|
+
public readonly CollectionPoolDiagnostics IntSets;
|
|
27
|
+
|
|
28
|
+
/// <summary>Typed handler <c>InstanceId -> priority-cache</c> dictionary pool diagnostics.</summary>
|
|
29
|
+
public readonly CollectionPoolDiagnostics TypedHandlerContextDicts;
|
|
30
|
+
|
|
31
|
+
/// <summary>Typed handler priority-cache dictionary pool diagnostics.</summary>
|
|
32
|
+
public readonly CollectionPoolDiagnostics TypedHandlerPriorityDicts;
|
|
33
|
+
|
|
34
|
+
internal PoolDiagnosticsSnapshot(
|
|
35
|
+
CollectionPoolDiagnostics instanceIdDicts,
|
|
36
|
+
CollectionPoolDiagnostics instanceIdLists,
|
|
37
|
+
CollectionPoolDiagnostics instanceIdSets,
|
|
38
|
+
CollectionPoolDiagnostics objectLists,
|
|
39
|
+
CollectionPoolDiagnostics objectStacks,
|
|
40
|
+
CollectionPoolDiagnostics intSets,
|
|
41
|
+
CollectionPoolDiagnostics typedHandlerContextDicts,
|
|
42
|
+
CollectionPoolDiagnostics typedHandlerPriorityDicts
|
|
43
|
+
)
|
|
44
|
+
{
|
|
45
|
+
InstanceIdDicts = instanceIdDicts;
|
|
46
|
+
InstanceIdLists = instanceIdLists;
|
|
47
|
+
InstanceIdSets = instanceIdSets;
|
|
48
|
+
ObjectLists = objectLists;
|
|
49
|
+
ObjectStacks = objectStacks;
|
|
50
|
+
IntSets = intSets;
|
|
51
|
+
TypedHandlerContextDicts = typedHandlerContextDicts;
|
|
52
|
+
TypedHandlerPriorityDicts = typedHandlerPriorityDicts;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Pooling
|
|
2
|
+
{
|
|
3
|
+
using System.Diagnostics;
|
|
4
|
+
using System.Runtime.CompilerServices;
|
|
5
|
+
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Default <see cref="IDxMessagingClock"/> backed by a process-lifetime
|
|
8
|
+
/// <see cref="Stopwatch"/>. Monotonic and Unity-agnostic so it works in
|
|
9
|
+
/// EditMode, PlayMode, and standalone test harnesses.
|
|
10
|
+
/// </summary>
|
|
11
|
+
public sealed class StopwatchClock : IDxMessagingClock
|
|
12
|
+
{
|
|
13
|
+
/// <summary>Shared instance. Stopwatch is lock-free and safe to share.</summary>
|
|
14
|
+
public static readonly StopwatchClock Instance = new();
|
|
15
|
+
|
|
16
|
+
private static readonly double TicksToSeconds = 1.0 / Stopwatch.Frequency;
|
|
17
|
+
|
|
18
|
+
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
|
|
19
|
+
|
|
20
|
+
/// <inheritdoc />
|
|
21
|
+
public double NowSeconds
|
|
22
|
+
{
|
|
23
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
24
|
+
get => _stopwatch.ElapsedTicks * TicksToSeconds;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Pooling
|
|
2
|
+
{
|
|
3
|
+
#if UNITY_2021_3_OR_NEWER
|
|
4
|
+
using System.Runtime.CompilerServices;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Unity-only <see cref="IDxMessagingClock"/> backed by
|
|
9
|
+
/// <see cref="Time.realtimeSinceStartupAsDouble"/>. Use this when sweep cadence
|
|
10
|
+
/// should follow Unity wall time rather than the AppDomain Stopwatch (Stopwatch
|
|
11
|
+
/// keeps running across editor pause; Time.realtimeSinceStartupAsDouble also
|
|
12
|
+
/// runs across pause but is the canonical Unity clock).
|
|
13
|
+
/// </summary>
|
|
14
|
+
/// <remarks>
|
|
15
|
+
/// Must be invoked from the Unity main thread; the underlying <c>Time</c>
|
|
16
|
+
/// API throws when called from worker threads.
|
|
17
|
+
/// </remarks>
|
|
18
|
+
public sealed class UnityRealtimeClock : IDxMessagingClock
|
|
19
|
+
{
|
|
20
|
+
/// <summary>Shared instance.</summary>
|
|
21
|
+
public static readonly UnityRealtimeClock Instance = new();
|
|
22
|
+
|
|
23
|
+
/// <inheritdoc />
|
|
24
|
+
public double NowSeconds
|
|
25
|
+
{
|
|
26
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
27
|
+
get => Time.realtimeSinceStartupAsDouble;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
#endif
|
|
31
|
+
}
|
package/Runtime/Core.meta
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: b58cce05d4f7d9447a63e82e2169f927
|
|
3
|
-
folderAsset: yes
|
|
4
|
-
DefaultImporter:
|
|
5
|
-
externalObjects: {}
|
|
6
|
-
userData:
|
|
7
|
-
assetBundleName:
|
|
8
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: b58cce05d4f7d9447a63e82e2169f927
|
|
3
|
+
folderAsset: yes
|
|
4
|
+
DefaultImporter:
|
|
5
|
+
externalObjects: {}
|
|
6
|
+
userData:
|
|
7
|
+
assetBundleName:
|
|
8
|
+
assetBundleVariant:
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 689f1e1a8d9f4c34f9e3ab4e3f94ec37
|
|
3
|
-
MonoImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
serializedVersion: 2
|
|
6
|
-
defaultReferences: []
|
|
7
|
-
executionOrder: 0
|
|
8
|
-
icon: {instanceID: 0}
|
|
9
|
-
userData:
|
|
10
|
-
assetBundleName:
|
|
11
|
-
assetBundleVariant:
|
|
12
|
-
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 689f1e1a8d9f4c34f9e3ab4e3f94ec37
|
|
3
|
+
MonoImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
defaultReferences: []
|
|
7
|
+
executionOrder: 0
|
|
8
|
+
icon: {instanceID: 0}
|
|
9
|
+
userData:
|
|
10
|
+
assetBundleName:
|
|
11
|
+
assetBundleVariant:
|
|
12
|
+
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 6e7f0de58bcf4f64813ef3650910c653
|
|
3
|
-
MonoImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
serializedVersion: 2
|
|
6
|
-
defaultReferences: []
|
|
7
|
-
executionOrder: 0
|
|
8
|
-
icon: {instanceID: 0}
|
|
9
|
-
userData:
|
|
10
|
-
assetBundleName:
|
|
11
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 6e7f0de58bcf4f64813ef3650910c653
|
|
3
|
+
MonoImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
defaultReferences: []
|
|
7
|
+
executionOrder: 0
|
|
8
|
+
icon: {instanceID: 0}
|
|
9
|
+
userData:
|
|
10
|
+
assetBundleName:
|
|
11
|
+
assetBundleVariant:
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 1f3f2efbb7f4441ebde8b418d178885a
|
|
3
|
-
MonoImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
serializedVersion: 2
|
|
6
|
-
defaultReferences: []
|
|
7
|
-
executionOrder: 0
|
|
8
|
-
icon: {instanceID: 0}
|
|
9
|
-
userData:
|
|
10
|
-
assetBundleName:
|
|
11
|
-
assetBundleVariant:
|
|
12
|
-
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 1f3f2efbb7f4441ebde8b418d178885a
|
|
3
|
+
MonoImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
defaultReferences: []
|
|
7
|
+
executionOrder: 0
|
|
8
|
+
icon: {instanceID: 0}
|
|
9
|
+
userData:
|
|
10
|
+
assetBundleName:
|
|
11
|
+
assetBundleVariant:
|
|
12
|
+
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 978915f0cb9d43d99e46455ff38dc528
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 978915f0cb9d43d99e46455ff38dc528
|
|
3
3
|
timeCreated: 1761517485
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
namespace DxMessaging.Unity.Integrations.Reflex
|
|
3
3
|
{
|
|
4
4
|
#if REFLEX_PRESENT
|
|
5
|
+
using System;
|
|
5
6
|
using Core.MessageBus;
|
|
7
|
+
using Core.Pooling;
|
|
6
8
|
using global::Reflex.Attributes;
|
|
7
9
|
using global::Reflex.Core;
|
|
8
10
|
|
|
@@ -87,6 +89,77 @@ namespace DxMessaging.Unity.Integrations.Reflex
|
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
}
|
|
92
|
+
|
|
93
|
+
/// <summary>
|
|
94
|
+
/// Provides convenience helpers for wiring a <see cref="MessageBus"/> into Reflex containers.
|
|
95
|
+
/// Reflex's container builder defaults to public-only constructor scanning, so today the
|
|
96
|
+
/// bare <c>Bind<MessageBus>().AsSingleton()</c> pattern resolves through the public
|
|
97
|
+
/// parameterless constructor. This is fragile against future Reflex versions that broaden
|
|
98
|
+
/// scanning to non-public constructors -- always prefer the helper below for clarity and
|
|
99
|
+
/// forward compatibility.
|
|
100
|
+
/// </summary>
|
|
101
|
+
public static class ReflexRegistrationExtensions
|
|
102
|
+
{
|
|
103
|
+
/// <summary>
|
|
104
|
+
/// Registers a singleton <see cref="MessageBus"/> exposed as <see cref="IMessageBus"/>
|
|
105
|
+
/// using an explicit factory.
|
|
106
|
+
/// </summary>
|
|
107
|
+
/// <param name="builder">Container builder receiving the registration.</param>
|
|
108
|
+
public static void AddDxMessagingBus(this ContainerBuilder builder)
|
|
109
|
+
{
|
|
110
|
+
if (builder == null)
|
|
111
|
+
{
|
|
112
|
+
throw new ArgumentNullException(nameof(builder));
|
|
113
|
+
}
|
|
114
|
+
builder.AddSingleton(_ => new MessageBus(), typeof(MessageBus), typeof(IMessageBus));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/// <summary>
|
|
118
|
+
/// Registers a singleton <see cref="MessageBus"/> exposed as <see cref="IMessageBus"/>
|
|
119
|
+
/// using the supplied factory. Allows callers to inject a custom
|
|
120
|
+
/// <see cref="IDxMessagingClock"/> via <see cref="MessageBus.CreateForInternalUse"/>.
|
|
121
|
+
/// </summary>
|
|
122
|
+
/// <param name="builder">Container builder receiving the registration.</param>
|
|
123
|
+
/// <param name="factory">Delegate that constructs the <see cref="MessageBus"/> instance using the resolver.</param>
|
|
124
|
+
public static void AddDxMessagingBus(
|
|
125
|
+
this ContainerBuilder builder,
|
|
126
|
+
Func<Container, MessageBus> factory
|
|
127
|
+
)
|
|
128
|
+
{
|
|
129
|
+
if (builder == null)
|
|
130
|
+
{
|
|
131
|
+
throw new ArgumentNullException(nameof(builder));
|
|
132
|
+
}
|
|
133
|
+
if (factory == null)
|
|
134
|
+
{
|
|
135
|
+
throw new ArgumentNullException(nameof(factory));
|
|
136
|
+
}
|
|
137
|
+
builder.AddSingleton(factory, typeof(MessageBus), typeof(IMessageBus));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// <summary>
|
|
141
|
+
/// Registers a singleton <see cref="MessageBus"/> exposed as <see cref="IMessageBus"/>
|
|
142
|
+
/// using the supplied <see cref="IDxMessagingClock"/>.
|
|
143
|
+
/// </summary>
|
|
144
|
+
/// <param name="builder">Container builder receiving the registration.</param>
|
|
145
|
+
/// <param name="clock">Clock implementation injected into the bus. Must not be null.</param>
|
|
146
|
+
public static void AddDxMessagingBus(this ContainerBuilder builder, IDxMessagingClock clock)
|
|
147
|
+
{
|
|
148
|
+
if (builder == null)
|
|
149
|
+
{
|
|
150
|
+
throw new ArgumentNullException(nameof(builder));
|
|
151
|
+
}
|
|
152
|
+
if (clock == null)
|
|
153
|
+
{
|
|
154
|
+
throw new ArgumentNullException(nameof(clock));
|
|
155
|
+
}
|
|
156
|
+
builder.AddSingleton(
|
|
157
|
+
_ => MessageBus.CreateForInternalUse(clock),
|
|
158
|
+
typeof(MessageBus),
|
|
159
|
+
typeof(IMessageBus)
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
90
163
|
#endif
|
|
91
164
|
}
|
|
92
165
|
#endif
|