FirebaseExtensions 10.1.0

dotnet add package FirebaseExtensions --version 10.1.0
                    
NuGet\Install-Package FirebaseExtensions -Version 10.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FirebaseExtensions" Version="10.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FirebaseExtensions" Version="10.1.0" />
                    
Directory.Packages.props
<PackageReference Include="FirebaseExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FirebaseExtensions --version 10.1.0
                    
#r "nuget: FirebaseExtensions, 10.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FirebaseExtensions@10.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FirebaseExtensions&version=10.1.0
                    
Install as a Cake Addin
#tool nuget:?package=FirebaseExtensions&version=10.1.0
                    
Install as a Cake Tool

Firebase Extensions for C# (.NET 10)

This library provides convenient extension methods for working with Google Cloud Firestore in your .NET applications, simplifying Firebase initialization, configuration inspection, and document/collection CRUD operations using the fluent ErrorOr pattern.

Installation

Ensure you have the following NuGet packages installed:

  • Google.Cloud.Firestore (4.4.0+)
  • ErrorOr (2.1.1+)
  • FirebaseAdmin (optional, for Firebase Admin features)

Firebase Project Setup

  1. Create a Firebase Project: If you don't have one already, create a project on the Firebase Console.
  2. Generate a Service Account Key:
    • In the Firebase console, navigate to Project settings → Service accounts.
    • Click Generate new private key.
    • Download the JSON credentials file and keep it secure.

Usage

1. Initializing Firebase and Firestore

You can initialize Firebase via the static Firebase.Current singleton or by registering IFirebase in your Dependency Injection container:

using ErrorOr;
using Fishman.Firebase.Extension;
using Google.Cloud.Firestore;

// 1. Specify the path to your service account JSON file
string serviceAccountPath = "path/to/your/serviceAccountKey.json";

// 2. Set the configuration path
ErrorOr<Success> pathResult = Firebase.Current.SetPathFile(serviceAccountPath);
if (pathResult.IsError)
{
    Console.WriteLine($"Failed to set path: {pathResult.FirstError.Description}");
    return;
}

// 3. Initialize Firestore (automatically reads project ID from JSON)
ErrorOr<Success> initResult = Firebase.Current.Init();
if (initResult.IsError)
{
    Console.WriteLine($"Initialization failed: {initResult.FirstError.Description}");
    return;
}

FirestoreDb? db = Firebase.Current.FirestoreDb;
Console.WriteLine($"Connected to Firestore project: {db?.ProjectId}");

2. Dependency Injection Support

Firebase implements IFirebase and provides a public constructor, making it simple to register in IServiceCollection:

services.AddSingleton<IFirebase, Firebase>();

3. Data Model Definition

To use custom C# classes with Firestore, always decorate them with [FirestoreData] and their properties with [FirestoreProperty]:

using Google.Cloud.Firestore;

[FirestoreData]
public class User
{
    [FirestoreProperty]
    public string Name { get; set; } = string.Empty;

    [FirestoreProperty]
    public int Age { get; set; }

    public User() { }

    public User(string name, int age)
    {
        Name = name;
        Age = age;
    }
}

4. Firestore CRUD Operations

All extension methods return ErrorOr<T> for predictable, exception-safe error handling.

using ErrorOr;
using Fishman.Firebase.Extension;
using Fishman.Firebase.Firestore;
using Google.Cloud.Firestore;

FirestoreDb db = Firebase.Current.FirestoreDb!;
DocumentReference docRef = db.Collection("Users").Document("user_123");

// CREATE / SET
User user = new("Oleg", 20);
ErrorOr<WriteResult> setResult = await docRef.SetValueAsync(user);
if (setResult.IsError)
{
    Console.WriteLine($"Set failed: {setResult.FirstError.Description}");
}

// READ / GET
ErrorOr<User> getResult = await docRef.GetValueAsync<User>();
if (getResult.IsError)
{
    Console.WriteLine($"Get failed: {getResult.FirstError.Description}");
}
else
{
    Console.WriteLine($"User: {getResult.Value.Name}, Age: {getResult.Value.Age}");
}

// UPDATE FIELDS
Dictionary<string, object> updates = new()
{
    { nameof(User.Age), 21 }
};
ErrorOr<WriteResult> updateResult = await docRef.UpdateFieldsAsync(updates);

// DELETE
ErrorOr<WriteResult> deleteResult = await docRef.DeleteValueAsync();

// COLLECTION OPERATIONS
CollectionReference colRef = db.Collection("Users");

// Add document with auto-generated ID
ErrorOr<DocumentReference> addResult = await colRef.AddValueAsync(new User("Anna", 28));

// Read all documents from collection
ErrorOr<IReadOnlyList<User>> allUsers = await colRef.GetAllValuesAsync<User>();
if (!allUsers.IsError)
{
    Console.WriteLine($"Found {allUsers.Value.Count} users.");
}

5. Reading Service Account Configuration

You can safely inspect properties from the loaded service account JSON without re-parsing files:

ErrorOr<string> projectId = Firebase.Current.GetProjectId();
ErrorOr<string> clientEmail = Firebase.Current.GetClientEmail();
ErrorOr<string> universeDomain = Firebase.Current.GetUniverseDomain();

6. Resource Cleanup

Firebase implements IDisposable to clean up cached JSON documents:

Firebase.Current.Dispose();
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.1.0 80 9/15/2026
10.0.0 427 11/24/2025
9.1.1 142 8/1/2025
9.1.0 143 7/19/2025
1.2.0 244 6/14/2024
1.0.1 175 6/6/2024
1.0.0 247 5/31/2024

Migrated to .NET 10 and ErrorOr 2.1.1. Added full CRUD operations (SetValueAsync, GetValueAsync, UpdateFieldsAsync, DeleteValueAsync, AddValueAsync, GetAllValuesAsync), DI support and thread safety.