diff --git a/Backblaze B2.sln b/Backblaze B2.sln index 7b5e9d9..e66e4d8 100644 --- a/Backblaze B2.sln +++ b/Backblaze B2.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backblaze.Client", "src\Cli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backblaze.Agent", "src\Agent\Backblaze.Agent.csproj", "{16C706DB-F611-4231-B061-F4B08DC8AAC1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backblaze.Agent.Autofac", "src\Agent.Autofac\Backblaze.Agent.Autofac.csproj", "{FB6CB27C-5529-424D-8570-B69BA35C8FC1}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backblaze.Tests.Unit", "test\Unit\Backblaze.Tests.Unit.csproj", "{6B57FB13-7D72-40D2-AE16-650A7B4990EC}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{9A70FFC5-6F45-48F6-8165-185D39517638}" @@ -37,6 +39,10 @@ Global {16C706DB-F611-4231-B061-F4B08DC8AAC1}.Debug|Any CPU.Build.0 = Debug|Any CPU {16C706DB-F611-4231-B061-F4B08DC8AAC1}.Release|Any CPU.ActiveCfg = Release|Any CPU {16C706DB-F611-4231-B061-F4B08DC8AAC1}.Release|Any CPU.Build.0 = Release|Any CPU + {FB6CB27C-5529-424D-8570-B69BA35C8FC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB6CB27C-5529-424D-8570-B69BA35C8FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB6CB27C-5529-424D-8570-B69BA35C8FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB6CB27C-5529-424D-8570-B69BA35C8FC1}.Release|Any CPU.Build.0 = Release|Any CPU {6B57FB13-7D72-40D2-AE16-650A7B4990EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6B57FB13-7D72-40D2-AE16-650A7B4990EC}.Debug|Any CPU.Build.0 = Debug|Any CPU {6B57FB13-7D72-40D2-AE16-650A7B4990EC}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/Agent.Autofac/Backblaze.Agent.Autofac.csproj b/src/Agent.Autofac/Backblaze.Agent.Autofac.csproj new file mode 100644 index 0000000..6e20d16 --- /dev/null +++ b/src/Agent.Autofac/Backblaze.Agent.Autofac.csproj @@ -0,0 +1,66 @@ + + + + netstandard2.0 + true + true + true + snupkg + logiclrd + Backblaze B2 Cloud Storage + 7.1 + Bytewizer.Backblaze + 1.0.0 + $(VersionPrefix)-$(VersionSuffix) + $(VersionPrefix) + 0 + $(VersionPrefix).$(BuildNumber) + $(VersionPrefix).$(BuildNumber) + $(AssemblyName) + Autofac integration for Backblaze.Client. + (c) 0000 Bytewizer. All rights reserved. + https://github.com/microcompiler/backblaze + https://github.com/microcompiler/backblaze + backblaze, b2, cloud-storage, api, csharp, storage-pod + + LICENSE.md + logo.png + README.md + NU5105 + + + + + true + + + + + + + + + + + + + + + True + + + + + + + + True + + + + + + + + + diff --git a/src/Agent.Autofac/ContainerBuilderExtensions.cs b/src/Agent.Autofac/ContainerBuilderExtensions.cs new file mode 100644 index 0000000..382e28c --- /dev/null +++ b/src/Agent.Autofac/ContainerBuilderExtensions.cs @@ -0,0 +1,75 @@ +using System; +using System.Net.Http; + +using Autofac; + +using Bytewizer.Backblaze.Client; +using Bytewizer.Backblaze.Handlers; + +using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace DQD.Backblaze.Agent.Autofac +{ + /// + /// Extension methods for setting up the agent in an Autofac . + /// + public static class ContainerBuilderExtensions + { + /// + /// Adds the repository agent services to the collection. + /// + /// The service collection. + /// Delegate to define the configuration. + public static ContainerBuilder AddBackblazeAgent(this ContainerBuilder services, Action setupBuilder) + { + if (services == null) + throw new ArgumentNullException(nameof(services)); + + if (setupBuilder == null) + throw new ArgumentNullException(nameof(setupBuilder)); + + var options = new ClientOptions(); + setupBuilder(options); + + return AddBackblazeAgent(services, options); + } + + /// + /// Adds the Backblaze client agent services to the collection. + /// + /// The service collection. + /// The agent options. + public static ContainerBuilder AddBackblazeAgent(this ContainerBuilder services, IClientOptions options) + { + if (services == null) + throw new ArgumentNullException(nameof(services)); + + if (options == null) + throw new ArgumentNullException(nameof(options)); + + options.Validate(); + + services.RegisterInstance(options).AsImplementedInterfaces(); + + services.RegisterType(); + services.RegisterType(); + + services.RegisterType().SingleInstance(); + + services.RegisterType(); + + var memoryCacheOptions = new MemoryCacheOptions(); + + services.RegisterInstance(Options.Create(memoryCacheOptions)).AsImplementedInterfaces(); + + services.RegisterInstance(LoggerFactory.Create(_ => { })).AsImplementedInterfaces().IfNotRegistered(typeof(ILoggerFactory)); + services.RegisterType().AsImplementedInterfaces(); + + services.RegisterType().As(); + + return services; + } + } +}