What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello, How to debug the following error ```Spryker\Glue\Kernel\ClassResolver\DependencyProvider\Depe

U047BQA5QPL
U047BQA5QPL Posts: 13 🧑🏻‍🚀 - Cadet

Hello,
How to debug the following error

Spryker\Glue\Kernel\ClassResolver\DependencyProvider\DependencyProviderNotFoundException - Exception: Spryker Kernel Exception
Can not resolve NgcategoryRestApiDependencyProvider for your module "NgcategoryRestApi"
You can fix this by adding the missing DependencyProvider to your module.

Comments

  • Alberto Reyer
    Alberto Reyer Posts: 690 🪐 - Explorer
    edited November 2022

    Create a file named NgcategoryRestApiDependencyProvider in the top level of your module, that looks like:

    <?php
    
    namespace Pyz\Glue\NgcategoryRestApi;
    
    use Spryker\Glue\Kernel\AbstractBundleDependencyProvider;
    use Spryker\Glue\Kernel\Container;
    
    /**
     * @method \Pyz\Glue\NgcategoryRestApi\NgcategoryRestApiConfig getConfig()
     */
    class NgcategoryRestApiDependencyProvider extends AbstractBundleDependencyProvider
    {
        /**
         * @param \Spryker\Glue\Kernel\Container $container
         *
         * @return \Spryker\Glue\Kernel\Container
         */
        public function provideDependencies(Container $container)
        {
            $container = parent::provideDependencies($container);
    
            return $container;
        }
    }
    
  • Your DependencyProvider must be at the root of your module
    • NgcategoryRestApi folder
    ◦ NgcategoryRestApiDependencyProvider.php
    ◦ NgcategoryRestApiConfig.php

  • U047BQA5QPL
    U047BQA5QPL Posts: 13 🧑🏻‍🚀 - Cadet

    Thanks for replay,
    I have already created the files withe the needful dependencies, I following category-rest-api module . Kindly provide more suggestions so that I can fix this.

  • Alberto Reyer
    Alberto Reyer Posts: 690 🪐 - Explorer
    edited November 2022

    You named the Dependency Provider NgcategoriesRestApiDependencyProvider, but your module is named NgcategoryRestApi so the correct name for the dependency provider would be NgcategoryRestApiDependencyProvider .
    You should stick to one name either singular or plural. Suggestion from Spryker is to stick with the plural form.

  • good catch @UL6DGRULR 👍

  • U047BQA5QPL
    U047BQA5QPL Posts: 13 🧑🏻‍🚀 - Cadet

    @UL6DGRULR Thankyou very much

    My bad, it was silly mistake by the way that error is gone but now another exception

  • U047BQA5QPL
    U047BQA5QPL Posts: 13 🧑🏻‍🚀 - Cadet

    NgcategoryRestApiDependencyProvider.php

    <?php
    
    namespace Pyz\Glue\NgcategoryRestApi;
    
    use Pyz\Glue\NgcategoryRestApi\Dependency\Client\NgcategoryRestApiToStoreClientBridge;
    use Pyz\Glue\NgcategoryRestApi\Dependency\Client\NgcategoryRestApiToCategoryStorageClientBridge;
    use Spryker\Glue\Kernel\AbstractBundleDependencyProvider;
    use Spryker\Glue\Kernel\Container;
    
    class NgcategoryRestApiDependencyProvider extends AbstractBundleDependencyProvider
    {
        /**
         * @var string
         */
        public const CLIENT_CATEGORY_STORAGE = 'CLIENT_CATEGORY_STORAGE';
    
        /**
         * @var string
         */
        public const CLIENT_STORE = 'CLIENT_STORE';
    
        /**
         * @param \Spryker\Glue\Kernel\Container $container
         *
         * @return \Spryker\Glue\Kernel\Container
         */
        public function provideDependencies(Container $container): Container
        {
            $container = parent::provideDependencies($container);
    
            $container = $this->addCategoryStorageClient($container);
    
            $container = $this->addStoreClient($container);
    
            return $container;
        }
    
        /**
         * @param \Spryker\Glue\Kernel\Container $container
         *
         * @return \Spryker\Glue\Kernel\Container
         */
        public function addCategoryStorageClient(Container $container)
        {
            $container->set(static::CLIENT_CATEGORY_STORAGE, function (Container $container) {
                return new NgcategoryRestApiToCategoryStorageClientBridge(
                    $container->getLocator()->categoryStorage()->client(),
                );
            });
        }
    
        /**
         * @param \Spryker\Glue\Kernel\Container $container
         *
         * @return \Spryker\Glue\Kernel\Container
         */
        protected function addStoreClient(Container $container): Container
        {
            $container->set(static::CLIENT_STORE, function (Container $container) {
                return new NgcategoryRestApiToStoreClientBridge(
                    $container->getLocator()->store()->client(),
                );
            });
    
            return $container;
        }
    }
    
  • Alberto Reyer
    Alberto Reyer Posts: 690 🪐 - Explorer
    edited November 2022
    1. don't use bridges on Project level, they are a workaround in the core for the missing interface segregation principle but are not necessary in the project as strict segregation is not a matter in the project namespace.
    2. Your issue is that addCategoryStorageClient does not return the container (doc block tells wrongly that it does), which is an issue the IDE already points out in line 41
  • Alberto Reyer
    Alberto Reyer Posts: 690 🪐 - Explorer

    Note: the stack trace exactly tells you the error that NULL is passed into addStoreClient, please read your error messages carefully before you ask for help.