Skip to content

Commit 21e5cea

Browse files
Add DI extension method to register NotionClient
1 parent 32a7165 commit 21e5cea

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using Notion.Client;
3+
4+
namespace Microsoft.Extensions.DependencyInjection
5+
{
6+
public static class ServiceCollectionExtensions
7+
{
8+
public static IServiceCollection AddNotionClient(this IServiceCollection services, Action<ClientOptions> options)
9+
{
10+
services.AddSingleton<INotionClient, NotionClient>(sp => {
11+
var clientOptions = new ClientOptions();
12+
options?.Invoke(clientOptions);
13+
14+
return NotionClientFactory.Create(clientOptions);
15+
});
16+
17+
return services;
18+
}
19+
}
20+
}

Src/Notion.Client/Notion.Client.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2424
<PackageReference Include="JsonSubTypes" Version="1.8.0" />
2525
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0"/>
26+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0"/>
2627
</ItemGroup>
2728

2829
<ItemGroup>

0 commit comments

Comments
 (0)