Skip to content

Commit 920b174

Browse files
committed
Added project Backblaze.Agent.Autofac with ContainerBuilderExtensions.cs.
1 parent dfd1288 commit 920b174

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

Backblaze B2.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backblaze.Client", "src\Cli
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backblaze.Agent", "src\Agent\Backblaze.Agent.csproj", "{16C706DB-F611-4231-B061-F4B08DC8AAC1}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backblaze.Agent.Autofac", "src\Agent.Autofac\Backblaze.Agent.Autofac.csproj", "{FB6CB27C-5529-424D-8570-B69BA35C8FC1}"
17+
EndProject
1618
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backblaze.Tests.Unit", "test\Unit\Backblaze.Tests.Unit.csproj", "{6B57FB13-7D72-40D2-AE16-650A7B4990EC}"
1719
EndProject
1820
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{9A70FFC5-6F45-48F6-8165-185D39517638}"
@@ -37,6 +39,10 @@ Global
3739
{16C706DB-F611-4231-B061-F4B08DC8AAC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
3840
{16C706DB-F611-4231-B061-F4B08DC8AAC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
3941
{16C706DB-F611-4231-B061-F4B08DC8AAC1}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{FB6CB27C-5529-424D-8570-B69BA35C8FC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{FB6CB27C-5529-424D-8570-B69BA35C8FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{FB6CB27C-5529-424D-8570-B69BA35C8FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{FB6CB27C-5529-424D-8570-B69BA35C8FC1}.Release|Any CPU.Build.0 = Release|Any CPU
4046
{6B57FB13-7D72-40D2-AE16-650A7B4990EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4147
{6B57FB13-7D72-40D2-AE16-650A7B4990EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
4248
{6B57FB13-7D72-40D2-AE16-650A7B4990EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
7+
<IncludeSymbols>true</IncludeSymbols>
8+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
9+
<Authors>logiclrd</Authors>
10+
<Product>Backblaze B2 Cloud Storage</Product>
11+
<LangVersion>7.1</LangVersion>
12+
<RootNamespace>Bytewizer.Backblaze</RootNamespace>
13+
<VersionPrefix>1.0.0</VersionPrefix>
14+
<Version Condition=" '$(Version)' == '' and '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
15+
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
16+
<BuildNumber Condition=" '$(BuildNumber)' == '' ">0</BuildNumber>
17+
<AssemblyVersion>$(VersionPrefix).$(BuildNumber)</AssemblyVersion>
18+
<FileVersion>$(VersionPrefix).$(BuildNumber)</FileVersion>
19+
<PackageId>$(AssemblyName)</PackageId>
20+
<Description>Autofac integration for Backblaze.Client.</Description>
21+
<Copyright>(c) 0000 Bytewizer. All rights reserved.</Copyright>
22+
<PackageProjectUrl>https://github.com/microcompiler/backblaze</PackageProjectUrl>
23+
<RepositoryUrl>https://github.com/microcompiler/backblaze</RepositoryUrl>
24+
<PackageTags>backblaze, b2, cloud-storage, api, csharp, storage-pod</PackageTags>
25+
<RepositoryType></RepositoryType>
26+
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
27+
<PackageIcon>logo.png</PackageIcon>
28+
<PackageReadmeFile>README.md</PackageReadmeFile>
29+
<NoWarn>NU5105</NoWarn>
30+
</PropertyGroup>
31+
32+
<!-- Github Properties -->
33+
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
34+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
35+
</PropertyGroup>
36+
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
38+
<DocumentationFile />
39+
</PropertyGroup>
40+
41+
<ItemGroup>
42+
<PackageReference Include="Autofac" Version="8.0.0" />
43+
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
44+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.0" />
45+
</ItemGroup>
46+
47+
<ItemGroup>
48+
<None Include="..\..\LICENSE.md" Link="LICENSE.md">
49+
<Pack>True</Pack>
50+
<PackagePath></PackagePath>
51+
</None>
52+
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
53+
</ItemGroup>
54+
55+
<ItemGroup>
56+
<None Include="..\..\images\logo.png">
57+
<Pack>True</Pack>
58+
<PackagePath></PackagePath>
59+
</None>
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<ProjectReference Include="..\Client\Backblaze.Client.csproj" />
64+
</ItemGroup>
65+
66+
</Project>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Net.Http;
3+
4+
using Autofac;
5+
6+
using Bytewizer.Backblaze.Client;
7+
using Bytewizer.Backblaze.Handlers;
8+
9+
using Microsoft.Extensions.Caching.Memory;
10+
using Microsoft.Extensions.Logging;
11+
using Microsoft.Extensions.Options;
12+
13+
namespace DQD.Backblaze.Agent.Autofac
14+
{
15+
/// <summary>
16+
/// Extension methods for setting up the agent in an Autofac <see cref="ContainerBuilder" />.
17+
/// </summary>
18+
public static class ContainerBuilderExtensions
19+
{
20+
/// <summary>
21+
/// Adds the repository agent services to the collection.
22+
/// </summary>
23+
/// <param name="services">The service collection.</param>
24+
/// <param name="setupBuilder">Delegate to define the configuration.</param>
25+
public static ContainerBuilder AddBackblazeAgent(this ContainerBuilder services, Action<IClientOptions> setupBuilder)
26+
{
27+
if (services == null)
28+
throw new ArgumentNullException(nameof(services));
29+
30+
if (setupBuilder == null)
31+
throw new ArgumentNullException(nameof(setupBuilder));
32+
33+
var options = new ClientOptions();
34+
setupBuilder(options);
35+
36+
return AddBackblazeAgent(services, options);
37+
}
38+
39+
/// <summary>
40+
/// Adds the Backblaze client agent services to the collection.
41+
/// </summary>
42+
/// <param name="services">The service collection.</param>
43+
/// <param name="options">The agent options.</param>
44+
public static ContainerBuilder AddBackblazeAgent(this ContainerBuilder services, IClientOptions options)
45+
{
46+
if (services == null)
47+
throw new ArgumentNullException(nameof(services));
48+
49+
if (options == null)
50+
throw new ArgumentNullException(nameof(options));
51+
52+
options.Validate();
53+
54+
services.RegisterInstance(options).AsImplementedInterfaces();
55+
56+
services.RegisterType<UserAgentHandler>();
57+
services.RegisterType<HttpErrorHandler>();
58+
59+
services.RegisterType<StorageService>().SingleInstance();
60+
61+
services.RegisterType<HttpClient>();
62+
63+
var memoryCacheOptions = new MemoryCacheOptions();
64+
65+
services.RegisterInstance(Options.Create(memoryCacheOptions)).AsImplementedInterfaces();
66+
67+
services.RegisterInstance(LoggerFactory.Create(_ => { })).AsImplementedInterfaces().IfNotRegistered(typeof(ILoggerFactory));
68+
services.RegisterType<MemoryCache>().AsImplementedInterfaces();
69+
70+
services.RegisterType<BackblazeClient>().As<IStorageClient>();
71+
72+
return services;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)