Some confusion about facades and factories


#1

I am doing some stuff with spryker middleware. To understand things better i installed akeneo pim with the AkeneoMiddlewareConnector which is using the spryker middleware.

Here i found the following code for a mapping stage plugin

protected function getMapperConfig(): MapperConfigTransfer
{
    return $this->getFacade()
        ->getCategoryImportMapperConfig();
}

In the process method in the same class

 public function process($payload, WriteStreamInterface $outStream, $originalPayload)
{
    return $this->getFactory()
        ->getProcessFacade()
        ->map($payload, $this->getMapperConfig());
}

For the first snippet : I understand that the MapperConfigTransfer is provided by the facade since this is business layer stuff.
I also understand that business stuff can’t get by using the BusinessFactory since we are in the CommunicationLayer and don’t have access to the BusinessLayer (and its factory).

For the second snippet: I understand that the process-facade is an external dependency and has to be loaded via factory and DependencyProvider.

What is not really clear to me …

The getProcessFacade() call is getting a facade from another module via the dependencyProvider. Up to this point i thought that facades are made for hiding business logic at all. To get those functionality public and usable by other modules, plugins are made to be instantiated and used in other modules.

So is it really clean to use “foreign” facades in other modules? Would it also be okay/better/possible to wrap it in a plugin?

It feels a bit like digging too deep when pulling something from one modules business layer to another modules communication layer.

Please excuse this basic question, if this is somewhere pointed out in the documentation, please let me know. I didn’t find anything yet.

Thanks


#2

Okay in addition to my post i found that the getProcessFacade() isn’t really getting the process facade directly. Instead there is another mediator class called “AkeneoPimMiddlewareConnectorToProcessFacadeBridge”. It just represents some functions of the real processFacade, but holds the real processFacade as a member. Is that additional layer introduced exactly because of my concerns? Otherwise i don’t see any sense to have this additional layer.

Best regards


#3

The Facade represents the public methods of a Module (~ part of Spryker’s “Internal API”). If you have a hard dependency on the project level to another module you should inject facade via DependencyProvider to your business model and use direct call of public methods. On the core level, we use bridges for this.

If you have some required logic you should use facade methods, but in case you have pluggable logic you should use plugins. That’s the difference.


#4

Ah okay, the bridges are used for calls on the core level. That was the missing part to understand why there is an additional bridge in between.

Many thanks