Skip to content

Commit e909426

Browse files
Create NotionClientFactory to create new client ♻️
* move creation of sub clients under factory method
1 parent 8b13761 commit e909426

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

Src/Notion.Client/NotionClient.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ public interface INotionClient
1212

1313
public class NotionClient : INotionClient
1414
{
15-
public NotionClient(ClientOptions options)
15+
public NotionClient(
16+
RestClient restClient,
17+
UsersClient users,
18+
DatabasesClient databases,
19+
PagesClient pages,
20+
SearchClient search,
21+
BlocksClient blocks)
1622
{
17-
RestClient = new RestClient(options);
18-
Users = new UsersClient(RestClient);
19-
Databases = new DatabasesClient(RestClient);
20-
Pages = new PagesClient(RestClient);
21-
Search = new SearchClient(RestClient);
22-
Blocks = new BlocksClient(RestClient);
23+
RestClient = restClient;
24+
Users = users;
25+
Databases = databases;
26+
Pages = pages;
27+
Search = search;
28+
Blocks = blocks;
2329
}
2430

2531
public IUsersClient Users { get; }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Notion.Client
2+
{
3+
public static class NotionClientFactory
4+
{
5+
public static NotionClient Create(ClientOptions options)
6+
{
7+
var restClient = new RestClient(options);
8+
9+
return new NotionClient(
10+
restClient: restClient
11+
, users: new UsersClient(restClient)
12+
, databases: new DatabasesClient(restClient)
13+
, pages: new PagesClient(restClient)
14+
, search: new SearchClient(restClient)
15+
, blocks: new BlocksClient(restClient)
16+
);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)