File tree Expand file tree Collapse file tree
src/extensions/BootstrapBlazor.TcpSocket/Extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,22 +28,6 @@ public static IServiceCollection AddBootstrapBlazorTcpSocketFactory(this IServic
2828 // 增加 ISocketClientProvider 服务
2929 services . TryAddTransient < ITcpSocketClientProvider , DefaultTcpSocketClientProvider > ( ) ;
3030
31- // 增加转换器集合配置服务
32- services . AddSocketDataConverters ( ) ;
33- return services ;
34- }
35-
36- /// <summary>
37- /// 增加 Socket 数据转换器集合配置项服务
38- /// </summary>
39- /// <param name="services"></param>
40- /// <returns></returns>
41- static IServiceCollection AddSocketDataConverters ( this IServiceCollection services )
42- {
43- services . AddOptions ( ) ;
44- services . TryAddSingleton < IOptionsChangeTokenSource < SocketDataConverterCollections > , ConfigurationChangeTokenSource < SocketDataConverterCollections > > ( ) ;
45- services . TryAddSingleton < IConfigureOptions < SocketDataConverterCollections > , ConfigureOptions < SocketDataConverterCollections > > ( ) ;
46-
4731 return services ;
4832 }
4933
Original file line number Diff line number Diff line change @@ -765,7 +765,23 @@ public async Task TryGetTypeConverter_Ok()
765765 var port = 8895 ;
766766 var server = StartTcpServer ( port , MockSplitPackageAsync ) ;
767767
768- var client = CreateClient ( ) ;
768+ var client = CreateClient ( builder =>
769+ {
770+ builder . Configure < SocketDataConverterCollections > ( options =>
771+ {
772+ options . AddTypeConverter < OptionConvertEntity > ( ) ;
773+ options . AddPropertyConverter < OptionConvertEntity > ( entity => entity . Header , new SocketDataPropertyConverterAttribute ( )
774+ {
775+ Offset = 0 ,
776+ Length = 5
777+ } ) ;
778+ options . AddPropertyConverter < OptionConvertEntity > ( entity => entity . Body , new SocketDataPropertyConverterAttribute ( )
779+ {
780+ Offset = 5 ,
781+ Length = 2
782+ } ) ;
783+ } ) ;
784+ } ) ;
769785 var tcs = new TaskCompletionSource ( ) ;
770786 var receivedBuffer = new byte [ 128 ] ;
771787
You can’t perform that action at this time.
0 commit comments