Architecture Components
The SDK is composed of six major components that work together:1. GraphServiceClient
The main entry point for all Microsoft Graph operations. This client object manages authentication and provides access to all API endpoints through request builders.2. Authentication Provider
Handles authentication and token acquisition. The SDK supports Azure.IdentityTokenCredential implementations, allowing flexible authentication strategies.
3. Request Adapter
Manages HTTP communication, serialization, and middleware processing. Built on Kiota abstractions, it handles request/response transformation.4. Request Builders
Provide fluent, strongly-typed navigation through the Microsoft Graph API structure. Request builders mirror the REST API path structure.5. Request Objects
Represent individual HTTP operations (GET, POST, PATCH, DELETE) with configurable options like query parameters and headers.6. Model Classes
Property bag objects for serialization/deserialization of Microsoft Graph resources. These are auto-generated from the Graph API metadata.Key Design Principles
Fluent API Design
The SDK uses a fluent interface that mirrors the Microsoft Graph REST API structure:Extensibility
Most components can be replaced with custom implementations:- Custom authentication providers
- Custom HTTP clients with middleware
- Custom request adapters
- Extension of model classes
Type Safety
Strong typing throughout the SDK helps catch errors at compile time:Request Flow
Understanding how a request flows through the SDK helps with debugging and customization:- Request Building: Start with
GraphServiceClientand chain request builders - Configuration: Apply query parameters, headers, and options
- Authentication: Request adapter invokes authentication provider for tokens
- Execution: HTTP request sent with proper headers and serialized body
- Response Handling: Deserialize JSON to strongly-typed model objects
- Error Handling: Errors throw
ODataErrorexceptions
Getting Started
To use the SDK effectively, you’ll need to understand:Authentication
Learn how to authenticate and configure credentials
GraphServiceClient
Explore client initialization and configuration
Request Builders
Navigate the API using request builders
Query Parameters
Filter, select, and customize your queries
Version Information
This documentation covers Microsoft Graph .NET SDK v5+, which uses the Kiota generation framework. Key differences from v4:- Built on Kiota abstractions instead of custom HTTP providers
- Direct support for Azure.Identity
TokenCredential - Simplified authentication with no separate auth library needed
- Request configuration pattern instead of request options
ODataErrorexceptions instead ofServiceException
Best Practices
Use async/await consistently
Use async/await consistently
All SDK methods are asynchronous. Always use
await and handle Task properly to avoid deadlocks.Handle errors with try-catch
Handle errors with try-catch
Always wrap SDK calls in try-catch blocks to handle
ODataError exceptions gracefully.Reuse GraphServiceClient instances
Reuse GraphServiceClient instances
The client is designed to be long-lived and thread-safe. Create one instance and reuse it throughout your application.
Use query parameters to reduce payload
Use query parameters to reduce payload
Select only the properties you need to minimize response size and improve performance.
Next Steps
Learn Authentication
Start with Authentication to understand how to set up credentials and scopes.
Initialize the Client
Learn how to create and configure a GraphServiceClient instance.
Make Your First Request
Use Request Builders to navigate and call the API.
