Example #1
0
 public HaWebSocketServer(ServiceConfigurationOption option,
                          IConnectionLifetimeManager connectionLifetimeManager,
                          IServiceProvider serviceProvider,
                          IInvokeHandlerManager invokeHandlerManager,
                          IUserIdProvider userIdProvider,
                          ILoggerFactory loggerFactory)
 {
     this.serviceConfigurationOption = option;
     this.connectionLifetimeManager  = connectionLifetimeManager;
     this.innerWebSocketServer       = new WebSocketServer(serviceConfigurationOption.Location);
     this.loggerFactory        = loggerFactory;
     this.simpleProtocol       = serviceProvider.GetRequiredService <ISimpleProtocol>();
     this.invokeHandlerManager = invokeHandlerManager;
     this.logger         = loggerFactory.CreateLogger <HaWebSocketServer>();
     this.userIdProvider = userIdProvider;
 }
        public HaWebSocketServer Build(Action <ServiceConfigurationOption> optionsAction)
        {
            if (optionsAction == null)
            {
                throw new Exception("option Action is Null");
            }

            this.serviceConfigurationOption = new ServiceConfigurationOption();

            optionsAction(this.serviceConfigurationOption);

            this.Services.AddSingleton <ServiceConfigurationOption>(serviceConfigurationOption);

            this.Services.AddTransient <IServiceProvider>(service => this.ServiceProvider);

            this.ServiceProvider = this.Services.BuildServiceProvider();

            return(this.ServiceProvider.GetRequiredService <HaWebSocketServer>());
        }