diff --git a/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs b/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs index 581bd728..eabb67dc 100644 --- a/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs +++ b/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Client.Clients; using PinguApps.Appwrite.Client.Internals; using PinguApps.Appwrite.Client.Utils; @@ -17,9 +16,9 @@ public class AccountClient : SessionAwareClientBase, IAccountClient private readonly IAccountApi _accountApi; private readonly Config _config; - public AccountClient(IServiceProvider services, Config config) + internal AccountClient(IAccountApi accountApi, Config config) { - _accountApi = services.GetRequiredService(); + _accountApi = accountApi; _config = config; } diff --git a/src/PinguApps.Appwrite.Client/Clients/DatabasesClient.cs b/src/PinguApps.Appwrite.Client/Clients/DatabasesClient.cs index b7a14ee9..06f0cb89 100644 --- a/src/PinguApps.Appwrite.Client/Clients/DatabasesClient.cs +++ b/src/PinguApps.Appwrite.Client/Clients/DatabasesClient.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Client.Internals; using PinguApps.Appwrite.Shared; using PinguApps.Appwrite.Shared.Requests.Databases; @@ -14,9 +13,9 @@ public class DatabasesClient : SessionAwareClientBase, IDatabasesClient { private readonly IDatabasesApi _databasesApi; - public DatabasesClient(IServiceProvider services) + internal DatabasesClient(IDatabasesApi databasesApi) { - _databasesApi = services.GetRequiredService(); + _databasesApi = databasesApi; } [ExcludeFromCodeCoverage] diff --git a/src/PinguApps.Appwrite.Client/Clients/TeamsClient.cs b/src/PinguApps.Appwrite.Client/Clients/TeamsClient.cs index a076aebb..9a6864df 100644 --- a/src/PinguApps.Appwrite.Client/Clients/TeamsClient.cs +++ b/src/PinguApps.Appwrite.Client/Clients/TeamsClient.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Client.Internals; using PinguApps.Appwrite.Client.Utils; using PinguApps.Appwrite.Shared; @@ -17,9 +16,9 @@ public class TeamsClient : SessionAwareClientBase, ITeamsClient private readonly ITeamsApi _teamsApi; private readonly Config _config; - public TeamsClient(IServiceProvider services, Config config) + internal TeamsClient(ITeamsApi teamsApi, Config config) { - _teamsApi = services.GetRequiredService(); + _teamsApi = teamsApi; _config = config; } diff --git a/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs b/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs index d2b79611..8c7d39c2 100644 --- a/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs +++ b/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs @@ -49,9 +49,23 @@ public static IServiceCollection AddAppwriteClient(this IServiceCollection servi .AddHttpMessageHandler() .AddHttpMessageHandler(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + var config = sp.GetRequiredService(); + return new AccountClient(api, config); + }); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + var config = sp.GetRequiredService(); + return new TeamsClient(api, config); + }); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + return new DatabasesClient(api); + }); services.AddSingleton(); services.AddSingleton(x => new Lazy(() => x.GetRequiredService())); @@ -88,9 +102,23 @@ public static IServiceCollection AddAppwriteClientForServer(this IServiceCollect .AddHttpMessageHandler() .ConfigurePrimaryHttpMessageHandler(ConfigurePrimaryHttpMessageHandler); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + var config = sp.GetRequiredService(); + return new AccountClient(api, config); + }); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + var config = sp.GetRequiredService(); + return new TeamsClient(api, config); + }); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + return new DatabasesClient(api); + }); services.AddSingleton(); return services; diff --git a/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs b/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs index 40efa473..f2847a6e 100644 --- a/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Server.Internals; using PinguApps.Appwrite.Server.Utils; using PinguApps.Appwrite.Shared; @@ -16,9 +15,9 @@ public class AccountClient : IAccountClient private readonly Config _config; - public AccountClient(IServiceProvider services, Config config) + internal AccountClient(IAccountApi accountApi, Config config) { - _accountApi = services.GetRequiredService(); + _accountApi = accountApi; _config = config; } diff --git a/src/PinguApps.Appwrite.Server/Clients/DatabasesClient.cs b/src/PinguApps.Appwrite.Server/Clients/DatabasesClient.cs index aeeff636..01db438c 100644 --- a/src/PinguApps.Appwrite.Server/Clients/DatabasesClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/DatabasesClient.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Server.Internals; using PinguApps.Appwrite.Shared; using PinguApps.Appwrite.Shared.Requests.Databases; @@ -16,9 +15,9 @@ public class DatabasesClient : IDatabasesClient { private readonly IDatabasesApi _databasesApi; - public DatabasesClient(IServiceProvider services) + internal DatabasesClient(IDatabasesApi databasesApi) { - _databasesApi = services.GetRequiredService(); + _databasesApi = databasesApi; } [ExcludeFromCodeCoverage] diff --git a/src/PinguApps.Appwrite.Server/Clients/TeamsClient.cs b/src/PinguApps.Appwrite.Server/Clients/TeamsClient.cs index c23acbab..b5786391 100644 --- a/src/PinguApps.Appwrite.Server/Clients/TeamsClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/TeamsClient.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Server.Internals; using PinguApps.Appwrite.Server.Utils; using PinguApps.Appwrite.Shared; @@ -17,9 +16,9 @@ public class TeamsClient : ITeamsClient private readonly ITeamsApi _teamsApi; private readonly Config _config; - public TeamsClient(IServiceProvider services, Config config) + internal TeamsClient(ITeamsApi teamsApi, Config config) { - _teamsApi = services.GetRequiredService(); + _teamsApi = teamsApi; _config = config; } diff --git a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs index 7822d28e..c0c1f7f5 100644 --- a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Server.Internals; using PinguApps.Appwrite.Server.Utils; using PinguApps.Appwrite.Shared; @@ -16,9 +15,9 @@ public class UsersClient : IUsersClient private readonly IUsersApi _usersApi; private readonly Config _config; - public UsersClient(IServiceProvider services, Config config) + internal UsersClient(IUsersApi usersApi, Config config) { - _usersApi = services.GetRequiredService(); + _usersApi = usersApi; _config = config; } diff --git a/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs b/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs index b40bb81e..c1f39084 100644 --- a/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs +++ b/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs @@ -54,10 +54,29 @@ public static IServiceCollection AddAppwriteServer(this IServiceCollection servi .AddHttpMessageHandler() .ConfigurePrimaryHttpMessageHandler(ConfigurePrimaryHttpMessageHandler); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + var config = sp.GetRequiredService(); + return new AccountClient(api, config); + }); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + var config = sp.GetRequiredService(); + return new UsersClient(api, config); + }); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + var config = sp.GetRequiredService(); + return new TeamsClient(api, config); + }); + services.AddSingleton(sp => + { + var api = sp.GetRequiredService(); + return new DatabasesClient(api); + }); services.AddSingleton(); return services; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.cs index 6b41629f..1221fce2 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.cs @@ -46,9 +46,7 @@ public void SetSession_UpdatesSession() // Arrange var sc = new ServiceCollection(); var mockAccountApi = new Mock(); - sc.AddSingleton(mockAccountApi.Object); - var sp = sc.BuildServiceProvider(); - var accountClient = new AccountClient(sp, new Config(TestConstants.Endpoint, TestConstants.ProjectId)); + var accountClient = new AccountClient(mockAccountApi.Object, new Config(TestConstants.Endpoint, TestConstants.ProjectId)); var sessionAware = accountClient as ISessionAware; // Act