Integration¶
Backend-for-frontend configuration¶
In order to receive the requests from the BFF we need to configure the Yarp
module and add exposed headers. First, go to appsettings.json
of your
application BFF and add the service to Service Discovery Providers.
Now add the following Yarp Routes configuration:
Also, we need to add a reference for the FileStorage BFF Client Module:
XML | |
---|---|
And add the dependency in the BFF Module:
C# | |
---|---|
Important
Remember to add your Application service to the FileStorage federations.json
located at FileStorage\ITsynch.Suite.FileStorage.Application\
.
Backend Integration¶
Imports¶
- Add the following import to
Domain
layer:
XML | |
---|---|
- Add the following import to
Application.Contracts
layer:
XML | |
---|---|
- Add the following import to
Application
layer:
XML | |
---|---|
- Depend on
FileStorageClientModule
in your Suite Application Module:
C# | |
---|---|
Update entities and consumer or saga¶
- In your domain entity implement
IHasAttachments
interface:
C# | |
---|---|
- In the corresponding GQL entity implement
IHasAttachments
interface from the GraphQL namespace:
C# | |
---|---|
- We need to update the MassTransit CreateOrUpdate message as well,
implementing the
IHasAttachmentsMessage
interface:
C# | |
---|---|
- Update your consumer/saga methods:
Note
The UpdateAttachments
method is an extension method from ITsynch.Suite.FileStorage.Abstractions
.
Also this method is idempotent, meaning that only the attachments from the
message will remain in the entity so this can be used in a creation or
an edition.
Now we have two separate ways to follow, depending if we have the GraphQL mutation in the backend service or in the Application service (E.g.: Admin Center).
Locate the GraphQL creation/update message record and implement IHasAttachment
interface:
C# | |
---|---|
Now we should have all the following classes with its GQL counterpart interfaced:
- Domain Entity
- GraphQL Domain Entity
- Creation/Update MT Message
- GraphQL Creation/Update MT Message
This is needed in order to not add any mappings since this is being mapped under the hood by implementing the interfaces.
You can check how all of this is implemented in Discussions or Admin Center.
Note
Remember to add new Migrations.
UI Integration¶
In order to add the Uploader to your component, first we need to add the
FileStorageUploaderModule
to your app module.
The first step is modify your Entity model and add the following properties:
TypeScript | |
---|---|
The Uploader supports multiple view types/modes and you can pass that
configuration through inputs, right now it supports cards
, chips
, carousel
view types and crud
or readonly
modes. Those inputs are optional, the
default values are cards
for type and crud
for mode. Example of
configuration:
TypeScript | |
---|---|
Creation Form Page¶
Now, if you want to implement it in your creation form page add the
customizeForm
method in your form constructor:
TypeScript | |
---|---|
Edition Form Page¶
Another example for the edition page (from Spares):
TypeScript | |
---|---|
Note
Keep in mind that the form control value of the Uploader component is an array
of file correlation IDs. So, you should add something like attachmentIds: string[]
to your entity in order to call mutations. You can check SpareEntity
for an example.
Template import¶
You can also add the component in your template, this way could be used if you only want to view the attached files to an entity.
HTML | |
---|---|
The property [files]
are the already uploaded files related to your entity and
the type is FileMetadata[]
.
Important
Do not forget to add the FileStorageUploaderModule
in your app module for this to work.
Events (Optional)¶
The File Storage Service
offers some message events which can be consumed to
be kept up to date with the state of a File
in case that you need it.
First of all, we need a reference to the FileStorage.Application.Contracts
project, as it's shown below:
XML | |
---|---|
You can consume the following events and perform the logic that you need in your respective service:
FileCreated
: This message is fired when aFile
has been created. It provides all theFile
metadata.
Note
If a File
upload is aborted/paused for more than 5 minutes (TBD), that
File will be deleted and the corresponding message event will also be fired.
FileUploaded
: This message is fired when aFile
is completely uploaded. Only provides theFile
Correlation Id.FileUpdated
: This message is fired when the metadata of aFile
was updated. Provides all the file metadata.FileDeleted
: This message is fired when aFile
has been deleted. Only provides theFile
Correlation Id.