From caecad307ab870226eed85fac5dcbdadefd1a9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 10 Jun 2020 15:13:04 +0300 Subject: [PATCH] Added Extra Configuration Options. --- docs/en/Blob-Storing-Custom-Provider.md | 87 +++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/docs/en/Blob-Storing-Custom-Provider.md b/docs/en/Blob-Storing-Custom-Provider.md index 02385a8061..281e5b32e1 100644 --- a/docs/en/Blob-Storing-Custom-Provider.md +++ b/docs/en/Blob-Storing-Custom-Provider.md @@ -88,3 +88,90 @@ Configure(options => }); ```` +### 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: + +````csharp + public class MyCustomBlobProviderConfiguration + { + public string MyOption1 + { + get => _containerConfiguration + .GetConfiguration("MyCustomBlobProvider.MyOption1"); + set => _containerConfiguration + .SetConfiguration("MyCustomBlobProvider.MyOption1", value); + } + + private readonly BlobContainerConfiguration _containerConfiguration; + + public MyCustomBlobProviderConfiguration( + BlobContainerConfiguration containerConfiguration) + { + _containerConfiguration = containerConfiguration; + } + } +```` + +Then you can change the `MyBlobContainerConfigurationExtensions` class like that: + +```` +public static class MyBlobContainerConfigurationExtensions +{ + public static BlobContainerConfiguration UseMyCustomBlobProvider( + this BlobContainerConfiguration containerConfiguration, + Action configureAction) + { + containerConfiguration.ProviderType = typeof(MyCustomBlobProvider); + + configureAction.Invoke( + new MyCustomBlobProviderConfiguration(containerConfiguration) + ); + + return containerConfiguration; + } + + public static MyCustomBlobProviderConfiguration GetMyCustomBlobProviderConfiguration( + this BlobContainerConfiguration containerConfiguration) + { + return new MyCustomBlobProviderConfiguration(containerConfiguration); + } +} +```` + +* Added an action parameter to the `UseMyCustomBlobProvider` method to allow developers to set the additional options. +* Added a new `GetMyCustomBlobProviderConfiguration` method to be used inside `MyCustomBlobProvider` class to obtain the configured values. + +Then anyone can set the `MyOption1` as shown below: + +````csharp +Configure(options => +{ + options.Containers.ConfigureDefault(container => + { + container.UseMyCustomBlobProvider(provider => + { + provider.MyOption1 = "my value"; + }); + }); +}); +```` + +Finally, you can access to the extra options using the `GetMyCustomBlobProviderConfiguration` method: + +````csharp +public class MyCustomBlobProvider : BlobProviderBase, ITransientDependency +{ + public override Task SaveAsync(BlobProviderSaveArgs args) + { + var config = args.Configuration.GetMyCustomBlobProviderConfiguration(); + var value = config.MyOption1; + + //... + } +} +```` + +## Contribute? + +If you create a new provider and you think it can be useful for other developers, please consider to [contribute](Contribution/Index.md) to the ABP Framework on GitHub. \ No newline at end of file