public function lookup(BeanContextInterface $beanManager, $className, array $args = array())
    {

        // load the object manager
        /** @var \AppserverIo\Psr\Di\ObjectManagerInterface $objectManager */
        $objectManager = $beanManager->getApplication()->search(ObjectManagerInterface::IDENTIFIER);

        // load the session ID from the environment
        $sessionId = Environment::singleton()->getAttribute(EnvironmentKeys::SESSION_ID);

        // query whether or not an object descriptor is available
        if ($objectManager->hasObjectDescriptor($className)) {
            // load the bean descriptor
            $descriptor = $objectManager->getObjectDescriptor($className);

            // query whether we've a SFSB
            if ($descriptor instanceof StatefulSessionBeanDescriptorInterface) {
                // try to load the stateful session bean from the bean manager
                if ($instance = $beanManager->lookupStatefulSessionBean($sessionId, $className)) {
                    // load the object manager and re-inject the dependencies
                    /** @var \AppserverIo\Psr\Di\ProviderInterface $provider */
                    $provider = $beanManager->getApplication()->search(ProviderInterface::IDENTIFIER);
                    $provider->injectDependencies($descriptor, $instance);

                    // we've to check for post-detach callbacks
                    foreach ($descriptor->getPostDetachCallbacks() as $postDetachCallback) {
                        $instance->$postDetachCallback();
                    }

                    // return the instance
                    return $instance;
                }

                // if not create a new instance and return it
                $instance = $beanManager->get($className);

                // we've to check for post-construct callbacks
                foreach ($descriptor->getPostConstructCallbacks() as $postConstructCallback) {
                    $instance->$postConstructCallback();
                }

                // return the instance
                return $instance;
            }

            // query whether we've a SSB
            if ($descriptor instanceof SingletonSessionBeanDescriptorInterface) {
                // try to load the singleton session bean from the bean manager
                if ($instance = $beanManager->lookupSingletonSessionBean($className)) {
                    // load the object manager and re-inject the dependencies
                    /** @var \AppserverIo\Psr\Di\ProviderInterface $provider */
                    $provider = $beanManager->getApplication()->search(ProviderInterface::IDENTIFIER);
                    $provider->injectDependencies($descriptor, $instance);

                    // we've to check for post-detach callbacks
                    foreach ($descriptor->getPostDetachCallbacks() as $postDetachCallback) {
                        $instance->$postDetachCallback();
                    }

                    // return the instance
                    return $instance;
                }

                // singleton session beans MUST extends \Stackable
                if (is_subclass_of($descriptor->getClassName(), '\Stackable') === false) {
                    throw new EnterpriseBeansException(sprintf('Singleton session bean %s MUST extend \Stackable', $descriptor->getClassName()));
                }

                // if not create a new instance and return it
                $instance = $beanManager->newSingletonSessionBeanInstance($className);

                // add the singleton session bean to the container
                $beanManager->getSingletonSessionBeans()->set($className, $instance);

                // we've to check for post-construct callback
                foreach ($descriptor->getPostConstructCallbacks() as $postConstructCallback) {
                    $instance->$postConstructCallback();
                }

                // return the instance
                return $instance;
            }

            // query whether we've a SLSB
            if ($descriptor instanceof StatelessSessionBeanDescriptorInterface) {
                // if not create a new instance and return it
                $instance = $beanManager->get($className);

                // we've to check for post-construct callback
                foreach ($descriptor->getPostConstructCallbacks() as $postConstructCallback) {
                    $instance->$postConstructCallback();
                }

                // return the instance
                return $instance;
            }

            //  query whether we've a MDB
            if ($descriptor instanceof MessageDrivenBeanDescriptorInterface) {
                // create a new instance and return it
                return $beanManager->get($className);
            }

            // query whether we simply have a bean
            if ($descriptor instanceof BeanDescriptorInterface) {
                // create the bean instance without the factory
                return $beanManager->get($className);
            }
        }

        // finally try to let the container create a new instance of the bean
        return $beanManager->newInstance($className);
    }