Feature: Google Drive Provider (ManagedCode.Storage.GoogleDrive)
Purpose
Expose Google Drive as IStorage so .NET apps can store files in Google Drive via the official Drive API while keeping OAuth/auth concerns in the hosting app:
- upload/download/list/delete through a consistent API
- keep auth concerns in the hosting app (you provide a
DriveService), while still allowing a swap point for tests
Main Flows
flowchart LR
App --> GD[GoogleDriveStorage : IGoogleDriveStorage]
GD --> Client[IGoogleDriveClient]
Client --> Drive[Google Drive API]
Components
- Storage:
- Client wrapper:
- Options / DI:
DI Wiring
dotnet add package ManagedCode.Storage.GoogleDrive
dotnet add package Google.Apis.Drive.v3
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Services;
using ManagedCode.Storage.GoogleDrive.Extensions;
var credential = GoogleCredential
.FromFile("service-account.json")
.CreateScoped(DriveService.Scope.Drive);
var driveService = new DriveService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "MyApp"
});
builder.Services.AddGoogleDriveStorageAsDefault(options =>
{
options.DriveService = driveService;
options.RootFolderId = "root";
});
Current Behavior
- You can provide either:
GoogleDriveStorageOptions.Client(customIGoogleDriveClientswap point, mainly for tests), orGoogleDriveStorageOptions.DriveService(official SDK client)
RootFolderIdscopes all operations (defaults toroot).
Tests
- HTTP/SDK-level fake:
- Storage behaviour via fake client:
- DI + provider plumbing:
Configuration Notes
See docs/Development/credentials.md and README.md for step-by-step instructions on Drive API credentials (service account or OAuth client).