Service Layers
Core Services (Singleton/Transient)
Registered in DI container viaServiceCollectionExtensions.AddIntuneCommanderCore():
| Service | Lifetime | Purpose |
|---|---|---|
IAuthenticationProvider | Singleton | Manages authentication logic |
IntuneGraphClientFactory | Singleton | Creates GraphServiceClient instances |
ProfileService | Singleton | Manages tenant profiles |
IProfileEncryptionService | Singleton | Encrypts/decrypts profile data |
ICacheService | Singleton | LiteDB-based cache for Graph responses |
IExportService | Transient | Export operations (new instance per operation) |
MainWindowViewModel | Transient | Main view model |
Graph API Services (Post-Authentication)
Important: Graph API services are NOT registered in the DI container. They are created inMainWindowViewModel after successful authentication.
Rationale:
- Services require an authenticated
GraphServiceClient - User may switch between multiple tenant profiles
- Services are tenant-specific, not application-wide
- Simpler lifecycle management
MainWindowViewModel are nullable (IConfigurationProfileService?) and only populated after ConnectToProfileAsync succeeds.
Graph Service Pattern
Every Graph API service follows a consistent pattern:Service Interface
List*Async()- Get all items (with manual pagination)Get*Async(string id)- Get single item by IDCreate*Async(T item)- Create new itemUpdate*Async(T item)- Update existing itemDelete*Async(string id)- Delete itemGetAssignmentsAsync(string id)- Get assignments for item
- Are
asyncand returnTaskorTask<T> - Accept
CancellationToken cancellationToken = defaultas last parameter - Use nullable return types where appropriate (
T?for Get methods)
Service Implementation
Manual Pagination Pattern
CRITICAL: Always manually implement pagination. Never usePageIterator as it silently truncates results on some tenants.
configurationPolicies(Settings Catalog):$top=100(Cosmos DB cursor stability)windowsQualityUpdateProfiles,windowsDriverUpdateProfiles:$top=200(hard API cap)- All other list endpoints:
$top=999(or default 200)
src/Intune.Commander.Core/Services/SettingsCatalogService.cs for an example with smaller page size.
Key Services
ProfileService
Purpose: Manages tenant profile storage and retrieval. Location:src/Intune.Commander.Core/Services/ProfileService.cs
Storage:
- File:
%LOCALAPPDATA%\Intune.Commander\profiles.json - Encrypted with
INTUNEMANAGER_ENC:prefix - Contains list of
TenantProfileobjects - Auto-migrates from legacy
IntuneManagerpath on first run
ProfileEncryptionService
Purpose: Encrypts and decrypts sensitive profile data using DataProtection. Location:src/Intune.Commander.Core/Services/ProfileEncryptionService.cs
Key Methods:
- Uses
Microsoft.AspNetCore.DataProtection - Keys stored at
%LOCALAPPDATA%\Intune.Commander\keys - DPAPI-protected on Windows
- File-system protected on macOS/Linux
CacheService
Purpose: LiteDB-based cache for Graph API responses. Location:src/Intune.Commander.Core/Services/CacheService.cs
Storage:
- File:
%LOCALAPPDATA%\Intune.Commander\cache.db(AES-encrypted) - Password: Generated once, stored encrypted in
cache-key.bin
IntuneGraphClientFactory
Purpose: Creates authenticatedGraphServiceClient instances with correct cloud endpoints.
Location: src/Intune.Commander.Core/Auth/IntuneGraphClientFactory.cs
Key Method:
| Cloud | Graph Endpoint | Authority Host |
|---|---|---|
| Commercial | https://graph.microsoft.com | AzureAuthorityHosts.AzurePublicCloud |
| GCC | https://graph.microsoft.com | AzureAuthorityHosts.AzurePublicCloud |
| GCC-High | https://graph.microsoft.us | AzureAuthorityHosts.AzureGovernment |
| DoD | https://dod-graph.microsoft.us | AzureAuthorityHosts.AzureGovernment |
ExportService
Purpose: Exports Intune policies to JSON files. Location:src/Intune.Commander.Core/Services/ExportService.cs
Export Format:
ImportService
Purpose: Imports policies from JSON files into target tenant. Location:src/Intune.Commander.Core/Services/ImportService.cs
Key Methods:
- Reads PowerShell export format
- Creates migration table mapping old IDs → new IDs
- Updates assignment references
- Preserves object relationships
All Graph API Services
Intune Commander includes 30+ Graph API services:Device Configuration
ConfigurationProfileService- Device configurationsSettingsCatalogService- Settings catalog policiesAdministrativeTemplateService- Admin templates (ADMX)AdmxFileService- Custom ADMX file uploads
Compliance
CompliancePolicyService- Compliance policiesComplianceScriptService- Custom compliance scripts
Endpoint Security
EndpointSecurityService- Endpoint security policies (Antivirus, Firewall, etc.)
Applications
ApplicationService- Mobile appsAppProtectionPolicyService- MAM policiesManagedAppConfigurationService- App configuration policies
Scripts
DeviceManagementScriptService- PowerShell scripts (Windows)DeviceHealthScriptService- Proactive remediation scriptsDeviceShellScriptService- Shell scripts (macOS)MacCustomAttributeService- macOS custom attributes
Updates
QualityUpdateProfileService- Windows quality updatesFeatureUpdateProfileService- Windows feature updatesDriverUpdateProfileService- Windows driver updates
Enrollment
EnrollmentConfigurationService- Enrollment configurationsAutopilotService- Windows Autopilot profilesAppleDepService- Apple DEP tokens
Identity & Access
ConditionalAccessPolicyService- Conditional Access policiesNamedLocationService- Named locationsAuthenticationStrengthService- Authentication strengthsAuthenticationContextService- Authentication contexts
Tenant Administration
RoleDefinitionService- RBAC role definitionsScopeTagService- Scope tagsAssignmentFilterService- Assignment filtersDeviceCategoryService- Device categoriesNotificationTemplateService- Notification templatesTermsAndConditionsService- Terms and conditionsIntuneBrandingService- Company portal branding
Directory
GroupService- Azure AD groupsUserService- Azure AD users
Cloud PC
CloudPcProvisioningService- Cloud PC provisioning policiesCloudPcUserSettingsService- Cloud PC user settings
Supporting Services
AssignmentCheckerService- Validates assignmentsDirectoryObjectResolver- Resolves group/user namesPermissionCheckService- Checks JWT token permissionsPolicySetService- Policy sets
Testing Services
Unit Testing Graph Services
Problem:GraphServiceClient is sealed and cannot be mocked.
Solution: Use reflection-based contract tests to verify interface conformance:
Integration Testing
For services that require actual Graph API calls:Service Conventions
Naming
- Interface:
I{Object}Service(e.g.,IConfigurationProfileService) - Implementation:
{Object}Service(e.g.,ConfigurationProfileService) - File location:
src/Intune.Commander.Core/Services/{Object}Service.cs
Constructor
Method Naming
- List:
List{Objects}Async()→Task<List<T>> - Get:
Get{Object}Async(string id)→Task<T?> - Create:
Create{Object}Async(T item)→Task<T> - Update:
Update{Object}Async(T item)→Task<T> - Delete:
Delete{Object}Async(string id)→Task - Assignments:
GetAssignmentsAsync(string id)→Task<List<Assignment>>
Cancellation
All async methods acceptCancellationToken cancellationToken = default as the last parameter.
Nullability
- Get methods return
Task<T?>(nullable) - List methods return
Task<List<T>>(empty list, not null) - Create/Update return
Task<T>(non-nullable, throw on failure)
Related Documentation
- Architecture Overview - Core architecture decisions
- Technology Stack - Dependencies and versions
- Testing - Service testing patterns
- Building - Build and run the application