docs: @Override
      public void registerListener(IServletContext isc) {
  
          CDIWebRuntime cdiWebRuntime = getCDIWebRuntime();
          if (cdiWebRuntime != null && cdiWebRuntime.isCdiEnabled(isc)) {
  
              BeanManager beanManager = cdiWebRuntime.getCurrentBeanManager();
              if (beanManager != null) {
  
                  /*
                   * Workaround jira https://issues.jboss.org/browse/WELD-1874
                   * To make sure that the WeldTerminalListener has the correct beanManager we
                   * have to pass a BeanManagerImpl into the constructor, however we do not
                   * know if we have a BeanManagerImpl or a BeanManagerProxy.
                   */
                  BeanManagerImpl beanManagerImpl = null;
  
                  if (beanManager instanceof BeanManagerProxy) {
                      BeanManagerProxy proxy = (BeanManagerProxy) beanManager;
                      beanManagerImpl = proxy.delegate();
                  } else if (beanManager instanceof BeanManagerImpl) {
                      beanManagerImpl = (BeanManagerImpl) beanManager;
                  } else {
                      throw new RuntimeException("Unexpected beanManager instance.");
                  }
  
                  isc.addListener(WeldListenerFactory.newWeldTerminalListener(beanManagerImpl));
                  //End of workaround.
  
                  if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                      Tr.debug(tc, "added WeldTerminalListener to the servlet context");
              }
  
          }
  
      }