sportradar / UnifiedOddsSdkNetCore

UnifiedFeed SDK is a client library that enables easier integration with the Betradar XML feeds. SDK exposes XML feed service interface in a more user-friendly way and isolates the client from having to do XML feed parsing, proper connection handling, error recovery, event queuing, data caching and dispatching.
https://sportradar.github.io/UnifiedOddsSdkNetCore/
Other
17 stars 14 forks source link

Fix: IDispatcherStore DI lifetime #30

Closed ridvandev closed 5 months ago

ridvandev commented 1 year ago

This commit addresses an issue where the IDispatcherStore was being shared between multiple IOddsFeedSession instances.

Currently, we utilize separate IOddsFeedSession objects for handling MessageInterest.LiveMessagesOnly and MessageInterest.PrematchMessagesOnly scenarios.

The code snippet below illustrates the session creation process:

_logger.LogInformation("Creating IOddsFeedSessions");
_oddsFeedPrematchSession = _oddsFeed.CreateBuilder()
    .SetMessageInterest(MessageInterest.PrematchMessagesOnly)
    .Build();
_oddsFeedLiveSession = _oddsFeed.CreateBuilder()
    .SetMessageInterest(MessageInterest.LiveMessagesOnly)
    .Build();

_logger.LogInformation("Creating entity specific dispatchers");
_prematchMatchDispatcher = _oddsFeedPrematchSession.CreateSportSpecificMessageDispatcher<IMatch>();
_prematchStageDispatcher = _oddsFeedPrematchSession.CreateSportSpecificMessageDispatcher<IStage>();
_prematchTournamentDispatcher = _oddsFeedPrematchSession.CreateSportSpecificMessageDispatcher<ITournament>();
_prematchBasicTournamentDispatcher = _oddsFeedPrematchSession.CreateSportSpecificMessageDispatcher<IBasicTournament>();
_prematchSeasonDispatcher = _oddsFeedPrematchSession.CreateSportSpecificMessageDispatcher<ISeason>();

_liveMatchDispatcher = _oddsFeedLiveSession.CreateSportSpecificMessageDispatcher<IMatch>();

Upon closer examination, it was discovered that the _oddsFeedLiveSession object was inadvertently sharing the same set of dispatchers as the _oddsFeedPrematchSession. Consequently, attempting to create a dispatcher for the _oddsFeedLiveSession led to an exception.

To resolve this issue, the proposed changes ensure that each session (_oddsFeedPrematchSession and _oddsFeedLiveSession) has its own set of distinct dispatchers, eliminating the exception and providing the expected behavior.