-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.cs
More file actions
53 lines (48 loc) · 2.25 KB
/
Copy pathSetup.cs
File metadata and controls
53 lines (48 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Microsoft.Extensions.DependencyInjection;
using Sa.HybridFileStorage.Domain;
namespace Sa.HybridFileStorage.FileSystem;
/// <summary>
/// Provides extension methods for registering the filesystem file storage provider with the .NET Generic Host.
/// </summary>
public static class Setup
{
/// <summary>
/// Registers the filesystem file storage provider using immutable <see cref="FileSystemStorageSettings"/>.
/// </summary>
/// <param name="services">The service collection to add the services to.</param>
/// <param name="options">Immutable settings for the filesystem storage provider.</param>
/// <returns>The same <see cref="IServiceCollection"/> instance with the service added.</returns>
public static IServiceCollection AddSaFileSystemFileStorage(
this IServiceCollection services,
FileSystemStorageSettings options)
{
services.AddSingleton<IFileStorage>(sp
=> new FileSystemStorage(options, sp.GetService<TimeProvider>()));
return services;
}
/// <summary>
/// Registers the filesystem file storage provider using a mutable options builder with fluent configuration.
/// </summary>
/// <param name="services">The service collection to add the services to.</param>
/// <param name="configure">An action that receives an <see cref="IServiceProvider"/> and a <see cref="FileSystemStorageOptions"/> instance for fluent configuration.</param>
/// <returns>The same <see cref="IServiceCollection"/> instance with the service added.</returns>
public static IServiceCollection AddSaFileSystemFileStorage(
this IServiceCollection services,
Action<IServiceProvider, FileSystemStorageOptions> configure)
{
services.AddSingleton<IFileStorage>(sp =>
{
FileSystemStorageOptions options = new();
configure.Invoke(sp, options);
options.Validate();
return new FileSystemStorage(new FileSystemStorageSettings
{
BasePath = options.BasePath,
IsReadOnly = options.IsReadOnly,
Basket = options.Basket,
StorageType = options.StorageType,
}, sp.GetService<TimeProvider>());
});
return services;
}
}