Browse Source

Introduce AbpBlobStoringOptions

pull/4105/head
Halil İbrahim Kalkan 6 years ago
parent
commit
1f41cd5671
  1. 12
      framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/AbpBlobStoringOptions.cs
  2. 9
      framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfiguration.cs
  3. 22
      framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurationDictionary.cs
  4. 29
      framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringOptions_Tests.cs
  5. 16
      framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs
  6. 12
      framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/TestContainer1.cs

12
framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/AbpBlobStoringOptions.cs

@ -0,0 +1,12 @@
namespace Volo.Abp.BlobStoring
{
public class AbpBlobStoringOptions
{
public BlobContainerConfigurationDictionary Containers { get; set; }
public AbpBlobStoringOptions()
{
Containers = new BlobContainerConfigurationDictionary();
}
}
}

9
framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfiguration.cs

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Volo.Abp.BlobStoring
{
public class BlobContainerConfiguration : Dictionary<string, object>
{
}
}

22
framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurationDictionary.cs

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.BlobStoring
{
public class BlobContainerConfigurationDictionary : Dictionary<string, BlobContainerConfiguration>
{
public BlobContainerConfigurationDictionary Configure<TContainer>(Action<BlobContainerConfiguration> configureAction)
{
return Configure(
BlobContainerNameAttribute.GetContainerName<TContainer>(),
configureAction
);
}
public BlobContainerConfigurationDictionary Configure(string name, Action<BlobContainerConfiguration> configureAction)
{
configureAction(this.GetOrAdd(name, () => new BlobContainerConfiguration()));
return this;
}
}
}

29
framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringOptions_Tests.cs

@ -0,0 +1,29 @@
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Shouldly;
using Xunit;
namespace Volo.Abp.BlobStoring
{
public class AbpBlobStoringOptions_Tests : AbpBlobStoringTestBase
{
private readonly AbpBlobStoringOptions _options;
public AbpBlobStoringOptions_Tests()
{
_options = GetRequiredService<IOptions<AbpBlobStoringOptions>>().Value;
}
[Fact]
public void Should_Property_Set_And_Get_Options_For_Different_Containers()
{
var testContainer1Config = _options.Containers
.GetOrDefault(BlobContainerNameAttribute.GetContainerName<TestContainer1>());
testContainer1Config.ShouldContainKeyAndValue("TestConfig1", "TestValue1");
var testContainer2Config = _options.Containers
.GetOrDefault(BlobContainerNameAttribute.GetContainerName<TestContainer2>());
testContainer2Config.ShouldContainKeyAndValue("TestConfig2", "TestValue2");
}
}
}

16
framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs

@ -8,6 +8,20 @@ namespace Volo.Abp.BlobStoring
)]
public class AbpBlobStoringTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBlobStoringOptions>(options =>
{
options.Containers
.Configure<TestContainer1>(container =>
{
container["TestConfig1"] = "TestValue1";
})
.Configure<TestContainer2>(container =>
{
container["TestConfig2"] = "TestValue2";
});
});
}
}
}

12
framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/TestContainer1.cs

@ -0,0 +1,12 @@
namespace Volo.Abp.BlobStoring
{
public class TestContainer1
{
}
public class TestContainer2
{
}
}
Loading…
Cancel
Save