Config
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
<PackageReference Include="DispatchR.Mediator" Version="2.1.1" />
|
||||
<PackageReference Include="MassTransit" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.5" />
|
||||
<PackageReference Include="X.PagedList" Version="10.5.9" />
|
||||
<PackageReference Include="X.PagedList.EF" Version="10.5.9" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
namespace Musify.Application.Configuration
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Musify.Application.Configuration
|
||||
{
|
||||
public class PlayListConfiguration
|
||||
{
|
||||
public const string SectionName = "PlayListConfiguration";
|
||||
|
||||
public PlayListRoutes Routes { get; set; } = new PlayListRoutes();
|
||||
|
||||
public int SmallPictureWidth { get; set; } = 128;
|
||||
@@ -15,6 +19,43 @@
|
||||
public int LargePictureWidth { get; private set; } = 512;
|
||||
|
||||
public int LargePictureHeight { get; private set; } = 512;
|
||||
|
||||
public PlayListConfiguration Load(IConfiguration configuration)
|
||||
{
|
||||
var section = configuration.GetSection(SectionName).Get<PlayListConfiguration>()
|
||||
?? throw new InvalidOperationException($"{SectionName} configuration section not found.");
|
||||
|
||||
Validate();
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
void Validate()
|
||||
{
|
||||
EnsureValue(Routes.ParentFolder, $"{SectionName}:BucketName");
|
||||
EnsureValue(Routes.SmallPictures, $"{SectionName}:Routes:SmallPictures");
|
||||
EnsureValue(Routes.MediumPictures, $"{SectionName}:Routes:MediumPictures");
|
||||
EnsureValue(Routes.LargePictures, $"{SectionName}:Routes:LargePictures");
|
||||
|
||||
EnsurePositiveValue(SmallPictureWidth, $"{SectionName}:SmallPictureWidth");
|
||||
EnsurePositiveValue(SmallPictureHeight, $"{SectionName}:SmallPictureHeight");
|
||||
EnsurePositiveValue(MediumPictureWidth, $"{SectionName}:MediumPictureWidth");
|
||||
EnsurePositiveValue(MediumPictureHeight, $"{SectionName}:MediumPictureHeight");
|
||||
EnsurePositiveValue(LargePictureWidth, $"{SectionName}:LargePictureWidth");
|
||||
EnsurePositiveValue(LargePictureHeight, $"{SectionName}:LargePictureHeight");
|
||||
}
|
||||
|
||||
void EnsureValue(string value, string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
throw new InvalidOperationException($"{name} configuration value not found.");
|
||||
}
|
||||
|
||||
void EnsurePositiveValue(int value, string name)
|
||||
{
|
||||
if (value < 1)
|
||||
throw new InvalidOperationException($"{name} configuration value must be a positive integer.");
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayListRoutes
|
||||
|
||||
@@ -1,10 +1,36 @@
|
||||
namespace Musify.Application.Configuration
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Musify.Application.Configuration
|
||||
{
|
||||
public class StorageConfiguration
|
||||
{
|
||||
public const string SectionName = "Storage";
|
||||
|
||||
public string BucketName { get; set; } = "musify-S3";
|
||||
|
||||
public StorageRoutes Routes { get; set; } = new StorageRoutes();
|
||||
|
||||
public StorageConfiguration Load(IConfiguration configuration)
|
||||
{
|
||||
var section = configuration.GetSection(SectionName).Get<StorageConfiguration>()
|
||||
?? throw new InvalidOperationException($"{SectionName} configuration section not found.");
|
||||
|
||||
Validate();
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
void Validate()
|
||||
{
|
||||
EnsureValue(BucketName, nameof(BucketName));
|
||||
EnsureValue(Routes.Uploads, $"{SectionName}:Route:Upload");
|
||||
}
|
||||
|
||||
void EnsureValue(string value, string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
throw new InvalidOperationException($"{name} configuration value not found.");
|
||||
}
|
||||
}
|
||||
|
||||
public class StorageRoutes
|
||||
|
||||
Reference in New Issue
Block a user