Repository navigation
How to ingegrate
Stefan edited this page Feb 14, 2023
·
2 revisions
- reference this package to your main project: https://www.nuget.org/packages/Samhammer.AzureBlobStorage/
- initialize the connection in Program.cs
- add the health check to Program.cs (optional)
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDefaultAzureBlobStorage(builder.Configuration);
builder.Services.AddHealthChecks()
.AddDefaultAzureBlobStorage() "AzureBlobStorageOptions": {
"ConnectionString": "DefaultEndpointsProtocol=https;AccountName=xxxxxx;AccountKey=xxxxxx;EndpointSuffix=core.windows.net",
"ContainerName": "DefaultContainerName"
},The samples above are suitable if you only need one storage account that is connected to your application.
Having multiple storage accounts is also supported by implementing multiple client factories.
public class MyClientFactory : IMyClientFactory
{
private IOptions<MyStorageOptions> Options { get; }
public MyClientFactory(IOptions<MyStorageOptions> options)
{
Options = options;
}
public BlobServiceClient GetClient(BlobClientOptions options = null)
{
return new BlobServiceClient(Options.Value.ConnectionString, options);
}
public string GetDefaultContainerName()
{
return Options.Value.ContainerName;
}
}
public interface IMyClientFactory : IAzureBlobStorageClientFactory
{
}The client and a matching service is then registered like that:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAzureBlobStorage<IMyClientFactory, MyClientFactory>(builder.Configuration);
builder.Services.AddHealthChecks()
.AddAzureBlobStorage<IMyClientFactory>()