-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathProviderExtensions.cs
More file actions
29 lines (25 loc) · 1.25 KB
/
ProviderExtensions.cs
File metadata and controls
29 lines (25 loc) · 1.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
using System;
using Microsoft.Extensions.DependencyInjection;
using ManagedCode.Storage.Core.Builders;
using ManagedCode.Storage.Core.Helpers;
using ManagedCode.Storage.Core;
using ManagedCode.Storage.Azure.Options;
namespace ManagedCode.Storage.Azure.Extensions
{
public static class ProviderExtensions
{
public static ProviderBuilder AddAzureBlobStorage<TAzureStorage>(
this ProviderBuilder providerBuilder,
Action<AzureBlobStorageConnectionOptions> action)
where TAzureStorage : IBlobStorage
{
var connectionOptions = new AzureBlobStorageConnectionOptions();
action.Invoke(connectionOptions);
var implementationType = TypeHelpers.GetImplementationType<TAzureStorage, AzureBlobStorage, AzureBlobStorageConnectionOptions>();
providerBuilder.ServiceCollection.AddScoped(typeof(TAzureStorage), x => Activator.CreateInstance(implementationType, connectionOptions));
// Because of AzureBlobStorage does not inherits TAzureStorage, DI complains on unability of casting
// providerBuilder.ServiceCollection.AddScoped(typeof(TAzureStorage), x => new AzureBlobStorage(connectionOptions));
return providerBuilder;
}
}
}