BLOB Storing: Creating a Custom Provider
This document explains how you can create a new storage provider for the BLOB storing system with an example.
Read the BLOB Storing document 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.
MyCustomBlobProvider
inherits from theBlobProviderBase
and overrides theabstract
methods. The actual implementation is up to you.- Implementing
ITransientDependency
registers this class to the Dependency Injection system as a transient service.
Notice: Naming conventions are important. If your class name doesn't end with
BlobProvider
, you must manually register/expose your service for theIBlobProvider
.
That's all. Now, you can configure containers (inside the ConfigureServices
method of your module) to use the MyCustomBlobProvider
class:
See the BLOB Storing document 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:
Then you can configure containers easier using the extension method:
Extra Configuration Options
BlobContainerConfiguration
allows to add/remove provider specific configuration objects. If your provider needs to additional configuration, you can create a wrapper class to the BlobContainerConfiguration
for a type-safe configuration option:
Then you can change the MyBlobContainerConfigurationExtensions
class like that:
- Added an action parameter to the
UseMyCustomBlobProvider
method to allow developers to set the additional options. - Added a new
GetMyCustomBlobProviderConfiguration
method to be used insideMyCustomBlobProvider
class to obtain the configured values.
Then anyone can set the MyOption1
as shown below:
Finally, you can access to the extra options using the GetMyCustomBlobProviderConfiguration
method:
Contribute?
If you create a new provider and you think it can be useful for other developers, please consider to contribute to the ABP Framework on GitHub.