Skip to content

Commit d259c70

Browse files
committed
Fix IConnection service factory
1 parent bfb8869 commit d259c70

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/THNETII.Octokit.DependencyInjection/GitHubServiceBuilder.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,16 @@ public GitHubServiceBuilder UseHttpClientFactoryConnection()
5656
: new HttpClientAdapter(httpFactory.CreateHandler);
5757
return adapter;
5858
});
59-
59+
Services.TryAddSingleton<IJsonSerializer, SimpleJsonSerializer>();
6060
Services.AddTransient<IConnection, Connection>(provider =>
6161
{
62-
var credStore = provider.GetService<ICredentialStore>();
63-
if (credStore is null)
64-
{
65-
return ActivatorUtilities.CreateInstance<Connection>(provider);
66-
}
67-
else
68-
{
69-
var serializer = provider.GetService<IJsonSerializer>()
62+
var credStore = provider.GetService<ICredentialStore>() ??
63+
new InMemoryCredentialStore(Credentials.Anonymous);
64+
var serializer = provider.GetService<IJsonSerializer>()
7065
?? new SimpleJsonSerializer();
71-
return ActivatorUtilities.CreateInstance<Connection>(
72-
provider, GitHubClient.GitHubApiUrl, credStore, serializer);
73-
}
66+
var client = provider.GetRequiredService<IHttpClient>();
67+
return ActivatorUtilities.CreateInstance<Connection>(
68+
provider, GitHubClient.GitHubApiUrl, credStore, client, serializer);
7469
});
7570
Services.AddTransient<IApiConnection, ApiConnection>();
7671

@@ -101,7 +96,7 @@ private static Dictionary<Type, Type> GetGitHubClientTypesWithImplementation()
10196
static void VisitAllClientTypes(Type interfaceType, Dictionary<Type, Type> knownTypes)
10297
{
10398
const BindingFlags ifPropBinding = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
104-
if (knownTypes.TryGetValue(interfaceType, out _))
99+
if (knownTypes.TryGetValue(interfaceType, out _))
105100
return; // Interface already known
106101

107102
if (FindImplementationType(interfaceType) is Type implType)

0 commit comments

Comments
 (0)