Exemple #1
0
        public static IServiceCollection AddFrameDispatcher(this IServiceCollection services, Action <BehaviorsBuilder> configure,
                                                            Action <DispatcherBuilder> configureProtocol = default)
        {
            var behaviors = new BehaviorsBuilder();

            configure(behaviors);

            services.TryAdd(behaviors._messageHandlers.Select(p => p.Item2));
            services.TryAddSingleton(sp =>
            {
                var dispatcher = new DispatcherBuilder(sp, behaviors);
                configureProtocol?.Invoke(dispatcher);
                return(dispatcher.Build());
            });

            return(services);
        }
Exemple #2
0
        public static IServiceCollection ConfigureFraming(this IServiceCollection services,
                                                          Action <BehaviorsBuilder> configureBehaviors,
                                                          Action <ServerFramingBuilder> configure)
        {
            var behaviors = new BehaviorsBuilder();

            configureBehaviors(behaviors);

            services.TryAdd(behaviors._messageHandlers.Select(p => p.Item2));
            services.AddOptions <ServerFramingOptions>()
            .Configure <IServiceProvider>((options, sp) =>
            {
                options.FramingBuilder = new ServerFramingBuilder(sp, behaviors);
                configure(options.FramingBuilder);
            });

            return(services);
        }
 public DispatcherBuilder(IServiceProvider serviceProvider, BehaviorsBuilder behaviors)
 {
     ApplicationServices = serviceProvider ?? throw new InvalidOperationException($"{nameof(IServiceProvider)} cannot be null !");
     _behaviors          = behaviors ?? throw new InvalidOperationException($"{nameof(BehaviorsBuilder)} cannot be null !");
     Decoder             = serviceProvider.GetService <IMessageReader>();
 }