as is
This commit is contained in:
34
StopShopping.FileApi/Services/Extensions.cs
Normal file
34
StopShopping.FileApi/Services/Extensions.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
using FileSignatures;
|
||||
using FileSignatures.Formats;
|
||||
using StopShopping.FileApi.Services.Implementions;
|
||||
|
||||
namespace StopShopping.FileApi.Services;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static IServiceCollection AddServices(this IServiceCollection services, IConfiguration appOptions)
|
||||
{
|
||||
services.Configure<AppOptions>(appOptions);
|
||||
services.AddValidation();
|
||||
|
||||
var imageFormats = FileFormatLocator.GetFormats().OfType<Image>();
|
||||
var imageInspector = new FileFormatInspector(imageFormats);
|
||||
services.AddSingleton<IFileFormatInspector>(imageInspector);
|
||||
|
||||
services.AddScoped<IFileService, FileService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static string GetTargetDirectory(this UploadScences uploadScences)
|
||||
{
|
||||
return uploadScences switch
|
||||
{
|
||||
UploadScences.Avatar => "avatar",
|
||||
UploadScences.Product => "product",
|
||||
UploadScences.Category => "category",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(uploadScences))
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user