Skip to content

Commit

Permalink
Added service registration extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
nikouu committed Oct 14, 2024
1 parent 89aa284 commit f0014d3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ZeroRedact/Redactors/Redactor.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace ZeroRedact
{
/// <inheritdoc />
/// <summary>
/// Implements redaction capabilities.
/// </summary>
[SkipLocalsInit]
public sealed partial class Redactor : IRedactor
{
Expand Down
6 changes: 5 additions & 1 deletion src/ZeroRedact/ZeroRedact.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<PackageId>Nikouu.ZeroRedact</PackageId>
<Version>2.2.0</Version>
<Version>2.3.0-alpha</Version>
<Title>Nikouu.ZeroRedact</Title>
<Authors>Niko Uusitalo</Authors>
<PackageProjectUrl>https://nikouu.github.io/ZeroRedact</PackageProjectUrl>
Expand Down Expand Up @@ -49,4 +49,8 @@
<_Parameter1>ZeroRedact.Benchmark</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
</ItemGroup>
</Project>
35 changes: 35 additions & 0 deletions src/ZeroRedact/ZeroRedactExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.Extensions.DependencyInjection;

namespace ZeroRedact
{
/// <summary>
/// Extension methods for <see cref="IServiceCollection"/> to register <see cref="IRedactor"/> with the <see cref="Redactor"/> implementation.
/// </summary>
public static class ZeroRedactExtensions
{
/// <summary>
/// Registers an instance of <see cref="IRedactor"/> with the <see cref="Redactor"/> implementation.
/// </summary>
/// <param name="services">The service collection</param>
/// <returns></returns>
public static IServiceCollection AddZeroRedact(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
services.AddSingleton<IRedactor, Redactor>();
return services;
}

/// <summary>
/// Registers an instance of <see cref="IRedactor"/> with the <see cref="Redactor"/> implementation with <see cref="RedactorOptions"/>.
/// </summary>
/// <param name="services">The service collection</param>
/// <param name="options">The <see cref="RedactorOptions"/> to configure the <see cref="Redactor"/></param>.
/// <returns></returns>
public static IServiceCollection AddZeroRedact(this IServiceCollection services, RedactorOptions options)
{
ArgumentNullException.ThrowIfNull(services);
services.AddSingleton<IRedactor>(new Redactor(options));
return services;
}
}
}

0 comments on commit f0014d3

Please # to comment.