From 1c735a84f49fbc1e90491dda2afd12cedf13e3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 10 Jun 2020 14:50:37 +0300 Subject: [PATCH] Complete BLOB Storing: Creating a Custom Provider. --- docs/en/Blob-Storing-Custom-Provider.md | 87 ++++++++++++++++++++++++- docs/en/Blob-Storing-File-System.md | 2 +- docs/en/Blob-Storing.md | 4 +- 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/docs/en/Blob-Storing-Custom-Provider.md b/docs/en/Blob-Storing-Custom-Provider.md index efd90c47f0..0f4ad5297a 100644 --- a/docs/en/Blob-Storing-Custom-Provider.md +++ b/docs/en/Blob-Storing-Custom-Provider.md @@ -1,3 +1,88 @@ # BLOB Storing: Creating a Custom Provider -TODO \ No newline at end of file +This document explains how you can create a new storage provider for the BLOB storing system with an example. + +> Read the [BLOB Storing document](Blob-Storing.md) to understand how to use the BLOB storing system. This document only covers how to create a new storage provider. + +## Example Implementation + +The first step is to create a class implements the `IBlobProvider` interface or inherit from the `BlobProviderBase` abstract class. + +````csharp +using System.IO; +using System.Threading.Tasks; +using Volo.Abp.BlobStoring; +using Volo.Abp.DependencyInjection; + +namespace AbpDemo +{ + public class MyCustomBlobProvider : BlobProviderBase, ITransientDependency + { + public override Task SaveAsync(BlobProviderSaveArgs args) + { + //TODO... + } + + public override Task DeleteAsync(BlobProviderDeleteArgs args) + { + //TODO... + } + + public override Task ExistsAsync(BlobProviderExistsArgs args) + { + //TODO... + } + + public override Task GetOrNullAsync(BlobProviderGetArgs args) + { + //TODO... + } + } +} +```` + +* `MyCustomBlobProvider` inherits from the `BlobProviderBase` and overrides the `abstract` methods. The actual implementation is up to you. +* Implementing `ITransientDependency` registers this class to the [Dependency Injection](Dependency-Injection.md) system as a transient service. + +That's all. Now, you can configure containers (inside the `ConfigureServices` method of your [module](Module-Development-Basics.md)) to use the `MyCustomBlobProvider` class: + +````csharp +Configure(options => +{ + options.Containers.ConfigureDefault(container => + { + container.ProviderType = typeof(MyCustomBlobProvider); + }); +}); +```` + +> See the [BLOB Storing document](Blob-Storing.md) if you want to configure a specific container. + +### BlobContainerConfiguration Extension Method + +If you want to provide a simpler configuration, create an extension method for the `BlobContainerConfiguration` class: + +```` +public static class MyBlobContainerConfigurationExtensions +{ + public static BlobContainerConfiguration UseMyCustomBlobProvider( + this BlobContainerConfiguration containerConfiguration) + { + containerConfiguration.ProviderType = typeof(MyCustomBlobProvider); + return containerConfiguration; + } +} +```` + +Then you can configure containers easier using the extension method: + +````csharp +Configure(options => +{ + options.Containers.ConfigureDefault(container => + { + container.UseMyCustomBlobProvider(); + }); +}); +```` + diff --git a/docs/en/Blob-Storing-File-System.md b/docs/en/Blob-Storing-File-System.md index 83102ffa05..15ecda4ed7 100644 --- a/docs/en/Blob-Storing-File-System.md +++ b/docs/en/Blob-Storing-File-System.md @@ -2,7 +2,7 @@ File System Storage Provider is used to store BLOBs in the local file system as standard files inside a folder. -> Read the BLOB Storing document to understand how to use the BLOB storing system. This document only covers how to configure containers to use the file system. +> Read the [BLOB Storing document](Blob-Storing.md) to understand how to use the BLOB storing system. This document only covers how to configure containers to use the file system. ## Installation diff --git a/docs/en/Blob-Storing.md b/docs/en/Blob-Storing.md index 5fab43cea4..4c944f5399 100644 --- a/docs/en/Blob-Storing.md +++ b/docs/en/Blob-Storing.md @@ -20,9 +20,9 @@ ABP Framework has the following storage provider implementations; * [Database](Blob-Storing-Database.md): Stores BLOBs in a database. * [Azure](Blob-Storing-Azure.md): Stores BLOBs on the [Azure BLOB storage](https://azure.microsoft.com/en-us/services/storage/blobs/). -More providers will be implemented by the time. You can [request](https://github.com/abpframework/abp/issues/new) it for your favorite provider or [create it yourself](Blob-Storing-Custom-Provider.md). +More providers will be implemented by the time. You can [request](https://github.com/abpframework/abp/issues/new) it for your favorite provider or [create it yourself](Blob-Storing-Custom-Provider.md) and [contribute](Contribution/Index.md) to the ABP Framework. -Multiple providers **can be used together** by the help of the **container system**, where each container can use a different provider (will be explained below). +Multiple providers **can be used together** by the help of the **container system**, where each container can uses a different provider. > BLOB storing system can not work unless you **configure a storage provider**. Refer to the linked documents for the storage provider configurations.