public void ListenForEvents(ServiceEnvironmentEventType eventType)
        {
            if (_eventListener == null)
            {
                _eventListener = new WcfHost(this, this);

                ServiceEndpoint[] rawEndpoints = _eventListener.Description.Endpoints.ToArray();
                _eventListener.Description.Endpoints.Clear();
                foreach (ServiceEndpoint endpoint in rawEndpoints)
                {
                    endpoint.Address = new EndpointAddress(new Uri(endpoint.Address.Uri.ToString().Replace("{guid}", Guid.NewGuid().ToString("N"))));
                    _eventListener.AddServiceEndpoint(endpoint);
                }

                _eventListener.Open();
            }

            var env = this.EnvironmentConfiguration;

            using (var connection = new SqlConnection(env.ConnectionString))
            {
                // FUTURE: in the future save all endpoints to DB
                var command = new SqlCommand(env.SP_EnvironmentEventRegister, connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@eventType", eventType.ToString());
                command.Parameters.AddWithValue("@endpointName", _eventListener.Description.Endpoints.First(endpoint => endpoint.Name == typeof(ServiceEnvironment).FullName).Name);
                command.Parameters.AddWithValue("@endpointAddress", _eventListener.Description.Endpoints.First(endpoint => endpoint.Name == typeof(ServiceEnvironment).FullName).Address.ToString());
                connection.Open();
                command.ExecuteNonQuery();
            }
        }
        // ------------------------------

        internal ServiceEnvironmentEventListener(ServiceEnvironment environment, ServiceEnvironmentEventType[] eventTypes)
        {
            this.ListenerID  = Guid.NewGuid();
            this.Environment = environment;
            this.EventTypes  = eventTypes;
            this.WcfHost     = new WcfHost(environment, this);

            ServiceEndpoint[] rawEndpoints = WcfHost.Description.Endpoints.ToArray();
            WcfHost.Description.Endpoints.Clear();
            foreach (ServiceEndpoint endpoint in rawEndpoints)
            {
                endpoint.Address = new EndpointAddress(new Uri(endpoint.Address.Uri.ToString().Replace("{guid}", this.ListenerID.ToString("N"))));
                WcfHost.AddServiceEndpoint(endpoint);
            }

            WcfHost.Open();
        }