-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from notion-dotnet/tech/50-add-ms-di-extension
Add Microsoft dependency injection extension for notion client 💖
- Loading branch information
Showing
7 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using Notion.Client; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddNotionClient(this IServiceCollection services, Action<ClientOptions> options) | ||
{ | ||
services.AddSingleton<INotionClient, NotionClient>(sp => | ||
{ | ||
var clientOptions = new ClientOptions(); | ||
options?.Invoke(clientOptions); | ||
|
||
return NotionClientFactory.Create(clientOptions); | ||
}); | ||
|
||
return services; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Notion.Client | ||
{ | ||
public static class NotionClientFactory | ||
{ | ||
public static NotionClient Create(ClientOptions options) | ||
{ | ||
var restClient = new RestClient(options); | ||
|
||
return new NotionClient( | ||
restClient: restClient | ||
, users: new UsersClient(restClient) | ||
, databases: new DatabasesClient(restClient) | ||
, pages: new PagesClient(restClient) | ||
, search: new SearchClient(restClient) | ||
, blocks: new BlocksClient(restClient) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters