Beispiel #1
0
        /// <summary>
        /// Creates a new instance of the RemotingServer class.
        /// </summary>
        /// <param name="config">Configuration settings to be used (Default configuration is used, if left null)</param>
        public RemotingServer(ServerConfig config = null)
        {
            _config = config ?? new ServerConfig();

            _uniqueServerInstanceName =
                string.IsNullOrWhiteSpace(_config.UniqueServerInstanceName)
                    ? Guid.NewGuid().ToString()
                    : _config.UniqueServerInstanceName;

            _serverInstances.AddOrUpdate(
                key: _config.UniqueServerInstanceName,
                addValueFactory: uniqueInstanceName => this,
                updateValueFactory: (uniqueInstanceName, oldServer) =>
            {
                oldServer?.Dispose();
                return(this);
            });

            SessionRepository =
                _config.SessionRepository ??
                new SessionRepository(
                    keySize: _config.KeySize,
                    inactiveSessionSweepInterval: _config.InactiveSessionSweepInterval,
                    maximumSessionInactivityTime: _config.MaximumSessionInactivityTime);

            _container = _config.DependencyInjectionContainer ?? new CastleWindsorDependencyInjectionContainer();
            Serializer = _config.Serializer ?? new BsonSerializerAdapter();
            MethodCallMessageBuilder = new MethodCallMessageBuilder();
            MessageEncryptionManager = new MessageEncryptionManager();

            _container.RegisterService <IDelegateProxyFactory, DelegateProxyFactory>(
                lifetime: ServiceLifetime.Singleton);

            _config.RegisterServicesAction?.Invoke(_container);

            Channel = _config.Channel ?? new WebsocketServerChannel();

            Channel.Init(this);

            if (_config.IsDefault)
            {
                RemotingServer.DefaultRemotingServer ??= this;
            }
        }