Calling Developers!
We are reenergizing our code contribution process! Learn More

What's the proper approach to using communication layer dependencies in console commands ? For busin

Options
U04RMV59JP8
U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
edited June 2023 in Spryker Development

What's the proper approach to using communication layer dependencies in console commands ? For business layer i was following __construct

Comments

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    What would you like to achieve?

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    Normally we just call the facade

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    I'm using a facade from another module and i want to use a function from there, which calls to factory>object>method. I've added it to the dependency provider but i'm not quite sure how to call the other module facade

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    Inside the console execute()?

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    Yes

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options
    $this->getFacade()->registerCustomer($newCustomer);
    
  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    Just use getFacade()

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    And it'll be auto wired.

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    edited March 2023
    Options

    That's going to catch both facades ?

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    getFacade() gets all of them

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    Okay, great, thanks

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    Hang on, I'm wrong.

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    I'll see what I can do

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    It attempts to access current module facade method and says it's undefined

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    i guess we both checked simultaneously ^_^

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    @U04RMV59JP8 sounds like a silly question but, why does one command rely on two facades?

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    Uses a function that was initially written in a different module but which does the exact same process that's needed in current module

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    Basically text parser was used in one module and then another module needed same processing and instead of duplicating the code I'm trying to use the same logic

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    Was talking about this earlier to a colleague, how about making a client layer and then using that?

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    So you share dependencies using a Zed request or something

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    I'll think about it, will ask colleagues and then decide

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 🧑🏻‍🚀 - Cadet
    Options

    So, yeah, i made the mistake of forgetting that i've already solved this in business layer via factory method that returns the facade via DI
    So i've just added the same thing to communication factory and got the facade that way. In case you were interested

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    @U04RMV59JP8 believe it or not I did the same thing today xD

  • U03SN9552JC
    U03SN9552JC Posts: 78 🧑🏻‍🚀 - Cadet
    Options

    Thanks for your help too