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

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

    What would you like to achieve?

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

    Normally we just call the facade

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

    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

    Inside the console execute()?

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yes

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet
    $this->getFacade()->registerCustomer($newCustomer);
    
  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

    Just use getFacade()

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

    And it'll be auto wired.

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited March 2023

    That's going to catch both facades ?

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

    getFacade() gets all of them

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

    Okay, great, thanks

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hang on, I'm wrong.

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

    I'll see what I can do

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

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

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

    i guess we both checked simultaneously ^_^

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

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

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

    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

    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

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

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

    So you share dependencies using a Zed request or something

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

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

  • U04RMV59JP8
    U04RMV59JP8 Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

    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

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

  • U03SN9552JC
    U03SN9552JC Posts: 78 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thanks for your help too