diff --git a/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs b/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs index eabb67dc..6852226d 100644 --- a/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs +++ b/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs @@ -1,6 +1,7 @@ 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; @@ -16,7 +17,7 @@ public class AccountClient : SessionAwareClientBase, IAccountClient private readonly IAccountApi _accountApi; private readonly Config _config; - internal AccountClient(IAccountApi accountApi, Config config) + internal AccountClient(IAccountApi accountApi, [FromKeyedServices("Client")] Config config) { _accountApi = accountApi; _config = config; diff --git a/src/PinguApps.Appwrite.Client/Clients/TeamsClient.cs b/src/PinguApps.Appwrite.Client/Clients/TeamsClient.cs index 9a6864df..55439273 100644 --- a/src/PinguApps.Appwrite.Client/Clients/TeamsClient.cs +++ b/src/PinguApps.Appwrite.Client/Clients/TeamsClient.cs @@ -1,6 +1,7 @@ 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; @@ -16,7 +17,7 @@ public class TeamsClient : SessionAwareClientBase, ITeamsClient private readonly ITeamsApi _teamsApi; private readonly Config _config; - internal TeamsClient(ITeamsApi teamsApi, Config config) + internal TeamsClient(ITeamsApi teamsApi, [FromKeyedServices("Client")] Config config) { _teamsApi = teamsApi; _config = config; diff --git a/src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs b/src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs index bc22abad..be304a90 100644 --- a/src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs +++ b/src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs @@ -1,6 +1,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Shared; namespace PinguApps.Appwrite.Client.Handlers; @@ -8,7 +9,7 @@ internal class HeaderHandler : DelegatingHandler { private readonly string _projectId; - public HeaderHandler(Config config) + public HeaderHandler([FromKeyedServices("Client")] Config config) { _projectId = config.ProjectId; } diff --git a/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs b/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs index 8c7d39c2..58b6d9d4 100644 --- a/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs +++ b/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs @@ -30,7 +30,7 @@ public static IServiceCollection AddAppwriteClient(this IServiceCollection servi { var customRefitSettings = AddSerializationConfigToRefitSettings(refitSettings); - services.AddSingleton(new Config(endpoint, projectId)); + services.AddKeyedSingleton("Client", new Config(endpoint, projectId)); services.AddTransient(); services.AddTransient(); @@ -52,13 +52,13 @@ public static IServiceCollection AddAppwriteClient(this IServiceCollection servi services.AddSingleton(sp => { var api = sp.GetRequiredService(); - var config = sp.GetRequiredService(); + var config = sp.GetRequiredKeyedService("Client"); return new AccountClient(api, config); }); services.AddSingleton(sp => { var api = sp.GetRequiredService(); - var config = sp.GetRequiredService(); + var config = sp.GetRequiredKeyedService("Client"); return new TeamsClient(api, config); }); services.AddSingleton(sp => @@ -84,7 +84,7 @@ public static IServiceCollection AddAppwriteClientForServer(this IServiceCollect { var customRefitSettings = AddSerializationConfigToRefitSettings(refitSettings); - services.AddSingleton(new Config(endpoint, projectId)); + services.AddKeyedSingleton("Client", new Config(endpoint, projectId)); services.AddTransient(); services.AddRefitClient(customRefitSettings) @@ -105,13 +105,13 @@ public static IServiceCollection AddAppwriteClientForServer(this IServiceCollect services.AddSingleton(sp => { var api = sp.GetRequiredService(); - var config = sp.GetRequiredService(); + var config = sp.GetRequiredKeyedService("Client"); return new AccountClient(api, config); }); services.AddSingleton(sp => { var api = sp.GetRequiredService(); - var config = sp.GetRequiredService(); + var config = sp.GetRequiredKeyedService("Client"); return new TeamsClient(api, config); }); services.AddSingleton(sp => diff --git a/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs b/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs index f2847a6e..afcd872c 100644 --- a/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Server.Internals; using PinguApps.Appwrite.Server.Utils; using PinguApps.Appwrite.Shared; @@ -15,7 +16,7 @@ public class AccountClient : IAccountClient private readonly Config _config; - internal AccountClient(IAccountApi accountApi, Config config) + internal AccountClient(IAccountApi accountApi, [FromKeyedServices("Server")] Config config) { _accountApi = accountApi; _config = config; diff --git a/src/PinguApps.Appwrite.Server/Clients/TeamsClient.cs b/src/PinguApps.Appwrite.Server/Clients/TeamsClient.cs index b5786391..80f00628 100644 --- a/src/PinguApps.Appwrite.Server/Clients/TeamsClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/TeamsClient.cs @@ -1,6 +1,7 @@ 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,7 +17,7 @@ public class TeamsClient : ITeamsClient private readonly ITeamsApi _teamsApi; private readonly Config _config; - internal TeamsClient(ITeamsApi teamsApi, Config config) + internal TeamsClient(ITeamsApi teamsApi, [FromKeyedServices("Server")] Config config) { _teamsApi = teamsApi; _config = config; diff --git a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs index c0c1f7f5..4f5470f2 100644 --- a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs @@ -1,6 +1,7 @@ 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; @@ -15,7 +16,7 @@ public class UsersClient : IUsersClient private readonly IUsersApi _usersApi; private readonly Config _config; - internal UsersClient(IUsersApi usersApi, Config config) + internal UsersClient(IUsersApi usersApi, [FromKeyedServices("Server")] Config config) { _usersApi = usersApi; _config = config; diff --git a/src/PinguApps.Appwrite.Server/Handlers/HeaderHandler.cs b/src/PinguApps.Appwrite.Server/Handlers/HeaderHandler.cs index 8ff5e2af..f55a0522 100644 --- a/src/PinguApps.Appwrite.Server/Handlers/HeaderHandler.cs +++ b/src/PinguApps.Appwrite.Server/Handlers/HeaderHandler.cs @@ -2,6 +2,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using PinguApps.Appwrite.Shared; namespace PinguApps.Appwrite.Server.Handlers; @@ -10,7 +11,7 @@ internal class HeaderHandler : DelegatingHandler private readonly string _projectId; private readonly string _apiKey; - public HeaderHandler(Config config) + public HeaderHandler([FromKeyedServices("Server")] Config config) { if (config.ApiKey is null) throw new ArgumentNullException("config.ApiKey"); diff --git a/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs b/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs index c1f39084..ad690f09 100644 --- a/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs +++ b/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs @@ -31,7 +31,7 @@ public static IServiceCollection AddAppwriteServer(this IServiceCollection servi { var customRefitSettings = AddSerializationConfigToRefitSettings(refitSettings); - services.AddSingleton(new Config(endpoint, projectId, apiKey)); + services.AddKeyedSingleton("Server", new Config(endpoint, projectId, apiKey)); services.AddTransient(); services.AddRefitClient(customRefitSettings) @@ -57,19 +57,19 @@ public static IServiceCollection AddAppwriteServer(this IServiceCollection servi services.AddSingleton(sp => { var api = sp.GetRequiredService(); - var config = sp.GetRequiredService(); + var config = sp.GetRequiredKeyedService("Server"); return new AccountClient(api, config); }); services.AddSingleton(sp => { var api = sp.GetRequiredService(); - var config = sp.GetRequiredService(); + var config = sp.GetRequiredKeyedService("Server"); return new UsersClient(api, config); }); services.AddSingleton(sp => { var api = sp.GetRequiredService(); - var config = sp.GetRequiredService(); + var config = sp.GetRequiredKeyedService("Server"); return new TeamsClient(api, config); }); services.AddSingleton(sp => diff --git a/src/PinguApps.Appwrite.Shared/Constants.cs b/src/PinguApps.Appwrite.Shared/Constants.cs index 38186e18..d9aaf4c3 100644 --- a/src/PinguApps.Appwrite.Shared/Constants.cs +++ b/src/PinguApps.Appwrite.Shared/Constants.cs @@ -1,5 +1,5 @@ namespace PinguApps.Appwrite.Shared; public static class Constants { - public const string Version = "0.4.5"; + public const string Version = "0.4.6"; }