-
Notifications
You must be signed in to change notification settings - Fork 34
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 #5733 from svrooij/main
Kiota with dependency injection dotnet
- Loading branch information
Showing
29 changed files
with
917 additions
and
0 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
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
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
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
46 changes: 46 additions & 0 deletions
46
get-started/dotnet-dependency-injection/GitHub/GitHubClient.cs
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,46 @@ | ||
// <auto-generated/> | ||
using GitHub.ApiClient.Repos; | ||
using Microsoft.Kiota.Abstractions.Extensions; | ||
using Microsoft.Kiota.Abstractions; | ||
using Microsoft.Kiota.Serialization.Form; | ||
using Microsoft.Kiota.Serialization.Json; | ||
using Microsoft.Kiota.Serialization.Multipart; | ||
using Microsoft.Kiota.Serialization.Text; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System; | ||
namespace GitHub.ApiClient | ||
{ | ||
/// <summary> | ||
/// The main entry point of the SDK, exposes the configuration and the fluent API. | ||
/// </summary> | ||
public class GitHubClient : BaseRequestBuilder | ||
{ | ||
/// <summary>The repos property</summary> | ||
public GitHub.ApiClient.Repos.ReposRequestBuilder Repos | ||
{ | ||
get => new GitHub.ApiClient.Repos.ReposRequestBuilder(PathParameters, RequestAdapter); | ||
} | ||
/// <summary> | ||
/// Instantiates a new <see cref="GitHub.ApiClient.GitHubClient"/> and sets the default values. | ||
/// </summary> | ||
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param> | ||
public GitHubClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary<string, object>()) | ||
{ | ||
ApiClientBuilder.RegisterDefaultSerializer<JsonSerializationWriterFactory>(); | ||
ApiClientBuilder.RegisterDefaultSerializer<TextSerializationWriterFactory>(); | ||
ApiClientBuilder.RegisterDefaultSerializer<FormSerializationWriterFactory>(); | ||
ApiClientBuilder.RegisterDefaultSerializer<MultipartSerializationWriterFactory>(); | ||
ApiClientBuilder.RegisterDefaultDeserializer<JsonParseNodeFactory>(); | ||
ApiClientBuilder.RegisterDefaultDeserializer<TextParseNodeFactory>(); | ||
ApiClientBuilder.RegisterDefaultDeserializer<FormParseNodeFactory>(); | ||
if (string.IsNullOrEmpty(RequestAdapter.BaseUrl)) | ||
{ | ||
RequestAdapter.BaseUrl = "https://api.github.com"; | ||
} | ||
PathParameters.TryAdd("baseurl", RequestAdapter.BaseUrl); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
get-started/dotnet-dependency-injection/GitHub/GitHubClientFactory.cs
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 GitHub.ApiClient; | ||
using Microsoft.Kiota.Abstractions.Authentication; | ||
using Microsoft.Kiota.Http.HttpClientLibrary; | ||
|
||
namespace GitHub; | ||
|
||
public class GitHubClientFactory | ||
{ | ||
private readonly IAuthenticationProvider _authenticationProvider; | ||
private readonly HttpClient _httpClient; | ||
|
||
public GitHubClientFactory(HttpClient httpClient) | ||
{ | ||
_authenticationProvider = new AnonymousAuthenticationProvider(); | ||
_httpClient = httpClient; | ||
} | ||
|
||
public GitHubClient GetClient() { | ||
return new GitHubClient(new HttpClientRequestAdapter(_authenticationProvider, httpClient: _httpClient)); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
get-started/dotnet-dependency-injection/GitHub/Models/Error.cs
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,73 @@ | ||
// <auto-generated/> | ||
using Microsoft.Kiota.Abstractions.Serialization; | ||
using Microsoft.Kiota.Abstractions; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System; | ||
namespace GitHub.ApiClient.Models | ||
{ | ||
#pragma warning disable CS1591 | ||
public class Error : ApiException, IAdditionalDataHolder, IParsable | ||
#pragma warning restore CS1591 | ||
{ | ||
/// <summary>Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.</summary> | ||
public IDictionary<string, object> AdditionalData { get; set; } | ||
/// <summary>The error documentation URL</summary> | ||
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER | ||
#nullable enable | ||
public string? DocumentationUrl { get; set; } | ||
#nullable restore | ||
#else | ||
public string DocumentationUrl { get; set; } | ||
#endif | ||
/// <summary>The error message</summary> | ||
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER | ||
#nullable enable | ||
public string? MessageEscaped { get; set; } | ||
#nullable restore | ||
#else | ||
public string MessageEscaped { get; set; } | ||
#endif | ||
/// <summary> | ||
/// Instantiates a new <see cref="GitHub.ApiClient.Models.Error"/> and sets the default values. | ||
/// </summary> | ||
public Error() | ||
{ | ||
AdditionalData = new Dictionary<string, object>(); | ||
} | ||
/// <summary> | ||
/// Creates a new instance of the appropriate class based on discriminator value | ||
/// </summary> | ||
/// <returns>A <see cref="GitHub.ApiClient.Models.Error"/></returns> | ||
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param> | ||
public static GitHub.ApiClient.Models.Error CreateFromDiscriminatorValue(IParseNode parseNode) | ||
{ | ||
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode)); | ||
return new GitHub.ApiClient.Models.Error(); | ||
} | ||
/// <summary> | ||
/// The deserialization information for the current model | ||
/// </summary> | ||
/// <returns>A IDictionary<string, Action<IParseNode>></returns> | ||
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() | ||
{ | ||
return new Dictionary<string, Action<IParseNode>> | ||
{ | ||
{ "documentation_url", n => { DocumentationUrl = n.GetStringValue(); } }, | ||
{ "message", n => { MessageEscaped = n.GetStringValue(); } }, | ||
}; | ||
} | ||
/// <summary> | ||
/// Serializes information the current object | ||
/// </summary> | ||
/// <param name="writer">Serialization writer to use to serialize this model</param> | ||
public virtual void Serialize(ISerializationWriter writer) | ||
{ | ||
_ = writer ?? throw new ArgumentNullException(nameof(writer)); | ||
writer.WriteStringValue("documentation_url", DocumentationUrl); | ||
writer.WriteStringValue("message", MessageEscaped); | ||
writer.WriteAdditionalData(AdditionalData); | ||
} | ||
} | ||
} |
Oops, something went wrong.