josephnhtam / live-streaming-server-net

A .NET implementation of RTMP live streaming server, supporting HTTP-FLV, WebSocket-FLV, HLS, Kubernetes, cloud storage services integration and more.
https://josephnhtam.github.io/live-streaming-server-net/
MIT License
139 stars 22 forks source link

Excessive use of IServiceProvider #24

Closed f135ta closed 6 months ago

f135ta commented 6 months ago

You have a very interesting approach to dependency injection, and coding in general.

The IServiceProvider has tripped me up several times when trying to work with the code. The nested dependencies make it difficult to understand which classes are actually used and where.

I'd suggest removing the IServiceProvider references and actually using the dependency injection built into Net Core properly. It will make the code easier to use, easier to test and easier to understand.

Microsoft recommendation for not using IServiceProvider

josephnhtam commented 6 months ago

Hi @f135ta

Thank you for your suggestion. I assume you are referring to the event dispatcher classes that use the observer or mediator pattern. In my opinion, it is not uncommon to inject the IoC container, the IServiceProvider, to dynamically obtain references to the required handlers, especially for these patterns. Moreover, this approach helps avoid circular references by eliminating the need for direct dependencies. However, any pull requests or discussions are very welcome.

josephnhtam commented 6 months ago

Unit tests have been added RtmpMessageDispatcher.Test.cs RtmpCommandDispatcher.Test.cs