MinIO .NET SDK

repository·master·Indexed 20 days ago

https://github.com/minio/minio-dotnet

A modern C# client library for interacting with MinIO and other S3-compatible object storage services. Supports .NET 8.0, 9.0, and 10.0, providing options for direct instantiation via MinioClientBuilder or integration with ASP.NET Core dependency injection using the .AddMinio extension method.

Tokens
1.3K
Snippets
7
Records
10
Agent score
22%

What's inside minio-dotnet

  1. Install and use the MinIO .NET SDK

    master

    The MinIO .NET SDK is a modern C# client library designed for interacting with MinIO or any S3-compatible object storage service.

    Requirements

    • .NET 8.0, 9.0, or 10.0
    • A running MinIO or S3-compatible server
  2. Configure MinIO with Dependency Injection

    master

    In modern .NET applications (like ASP.NET Core), you can register the MinIO client into the service collection using the .AddMinio(endpoint) extension method. This allows the client to be injected into your services via constructor injection.

    services
        .AddMinio("http://localhost:9000")
        .WithStaticCredentials("minioadmin", "minioadmin");
  3. Set up Visual Studio Code for MinIO .NET development

    master

    To develop with the MinIO .NET SDK in VS Code:

    1. Install the C# Dev Kit extension.
    2. Open the repository root folder; the minio-dotnet2.sln solution file should be detected automatically.
    3. Select the solution file when prompted to enable IntelliSense across all projects.

    Note: The repository includes pre-configured settings for debugging example projects.

  4. Set up JetBrains Rider for MinIO .NET development

    master

    JetBrains Rider provides native support for this project:

    1. Open minio-dotnet2.sln.
    2. Rider will automatically restore NuGet packages and index the solution.
    3. Use the built-in test runner (View → Tool Windows → Unit Tests) to run xUnit tests.
    4. Right-click any project in the Solution Explorer and select Run or Debug to execute example projects.
  5. Initialize MinIOClient using Direct Usage

    master

    For simple applications or scenarios where dependency injection is not used, you can instantiate the client directly using the MinioClientBuilder. You must provide the server endpoint and credentials via .WithStaticCredentials(accessKey, secretKey).

    var client = new MinioClientBuilder("https://minio.example.com")
        .WithStaticCredentials("accessKey", "secretKey")
        .Build();
  6. Install the .NET SDK

    master

    The MinIO .NET SDK targets net6.0 through net10.0. It is recommended to install .NET SDK 8.0 or later. Use the following commands based on your operating system:

    • Windows: Use winget or download the installer from the official Microsoft website.
    • macOS: Use Homebrew.
    • Linux (Debian/Ubuntu): Use apt-get.
    # Windows
    winget install Microsoft.DotNet.SDK.10
    
    # macOS
    brew install dotnet
    
    # Linux (Debian/Ubuntu)
    sudo apt-get update && sudo apt-get install -y dotnet-sdk-10.0
    
    # Verify installation
    dotnet --version
  7. Run a local MinIO server with Docker

    master

    The example projects require a running MinIO server. You can start a local instance using Docker with the following command. The default credentials for this setup are minioadmin / minioadmin.

    docker run --rm -p 9000:9000 quay.io/minio/minio:latest server /data
  8. Run MinIO SDK Examples

    master

    The repository includes two example projects to demonstrate different usage patterns:

    • Minio.Examples.Simple/: A minimal console application using the direct MinioClientBuilder pattern.
    • Minio.Examples.Host/: A DI-based example using IHost that demonstrates advanced operations like bucket creation, object upload/download, listing, and bucket notifications.

    Setup Steps

    1. Start a local MinIO instance using Docker:

      docker run --rm -p 9000:9000 quay.io/minio/minio:latest server /data
    2. Run the examples using the .NET CLI:

      # To run the simple console example
      dotnet run --project Minio.Examples.Simple
      
      # To run the DI-based host example
      dotnet run --project Minio.Examples.Host
    docker run --rm -p 9000:9000 quay.io/minio/minio:latest server /data
    
    # then
    dotnet run --project Minio.Examples.Simple
  9. Use Minio.Examples.Host for Dependency Injection and advanced features

    master

    The Minio.Examples.Host project demonstrates integration with Microsoft.Extensions.Hosting and the AddMinio DI extension. It covers:

    • Registering the MinIO client in an IHost service container.
    • Using Microsoft.Extensions.Logging for structured logging.
    • Creating buckets and performing parallel object writes (100 objects).
    • Reading objects as streams.
    • Listing objects using prefixes and page sizes.
    • Subscribing to real-time bucket notifications via IObservable<T>.

    You can target a specific .NET framework (e.g., net8.0) if needed.

    # Run the host example
    dotnet run --project Minio.Examples.Host
    
    # Run targeting a specific framework
    dotnet run --project Minio.Examples.Host --framework net8.0
  10. Use Minio.Examples.Simple for direct client usage

    master

    The Minio.Examples.Simple project is a minimal console application that demonstrates how to use MinioClientBuilder directly without dependency injection. It covers:

    • Creating a client with static credentials.
    • Checking for bucket existence and creating a bucket if it does not exist.
    dotnet run --project Minio.Examples.Simple