GcpHelpers 1.3.5

dotnet add package GcpHelpers --version 1.3.5
                    
NuGet\Install-Package GcpHelpers -Version 1.3.5
                    
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="GcpHelpers" Version="1.3.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GcpHelpers" Version="1.3.5" />
                    
Directory.Packages.props
<PackageReference Include="GcpHelpers" />
                    
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 GcpHelpers --version 1.3.5
                    
#r "nuget: GcpHelpers, 1.3.5"
                    
#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 GcpHelpers@1.3.5
                    
#: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=GcpHelpers&version=1.3.5
                    
Install as a Cake Addin
#tool nuget:?package=GcpHelpers&version=1.3.5
                    
Install as a Cake Tool

GcpHelpers

This repo is a collection of helper objects and tips for working with the GCP .NET Cloud Client Libraries. See Getting started with .NET on Google Cloud to get started, these tools are useful for more advanced uses.

Authentication

...

Firestore

Firestore serialization in the Google.Cloud.Firestore .NET library is already more extensive than in other languages. As documented in the Data model, in order for this serialization to work, you must decorate your objects with [Firestore*] properties as the examples show in the linked data model page.

If you try to use your own POCO and do not modify it to have the Firestore attributes:

    var doc = _firestore.Collection(_usersCollection)
        .Document(id);
    var snapshot = await doc.GetSnapshotAsync();

    if (snapshot != null)
        return snapshot.ConvertTo<MyUserType>();

You will get an exception System.ArgumentException: Unable to create converter for type MyUserType.

Personally putting implementation/provider specific attributes on my clean POCOs feels dirty to me. Also, if you are trying to use an existing data model you don't want to change that model just for Firestore. For example, you might want to have the flexibility to change providers; maybe use Mongo instead or another cloud database. Thankfully, there's an escape hatch for this; it's called a Custom Converter. After you build a custom converter you add it to the ConverterRegistry when creating a FirestoreDbBuilder as shown here.

The problem with this is that you need to create a converter for every type. The default serialization behavior I want is actually the same for every one, and hence we should use Generics. This repo implements a GenericFirestoreConverter<T> which is the default serialization I'd like to see and it just works for all my POCOs. You register is just like you would any other converter, except that it is a Generic and takes a type parameter of <T> for example:

    _firestore = new FirestoreDbBuilder
    {
        ProjectId = config["ProjectId"],
        ConverterRegistry = new ConverterRegistry
        {
            new GenericFirestoreConverter<MyUserType>("UserId"),
            new GenericFirestoreConverter<MyAddressType>("AddressId"),
            ...
        }
    }

You will also note that the constructor has an optional string parameter which is the name of the property that will be used as the FirestoreDocumentId.

Handling Collections

If your POCO has children, i.e. MyUserType has a member Addresses of type IEnumerable<MyAddressType>, this custom converter searches the ConverterRegistry and uses the converter you registered to handle deserialization recursively. Interestingly, this is not necesary for serialization.

Instance Metadata

...

API Gateway / OpenAPI with Swagger

...

Secret Manager

...

Logging

Now included in the Beta version of the Google SDK. To use add the folowing package to your .csproj

<PackageReference Include="Google.Cloud.Logging.Console" Version="1.0.0-beta01" />

Reference the package and add the formatter

using Google.Cloud.Logging.Console;
...

builder.Logging.AddGoogleCloudConsole();

nuget

This package is a public package available on nuget, to use the package:

dotnet add package GcpHelpers 

For developers maintaining the package, publish using the included wrapper shell script:

./publish.sh

You will need to login to your apikeys and get a key. Save this in a file called nuget-key in the root directory of this project.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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
1.3.5 406 1/1/2024
1.3.4 222 12/26/2023
1.3.3 235 11/13/2023
1.3.2 260 5/11/2023
1.3.1 215 5/9/2023
1.3.0 230 5/3/2023
1.2.0 265 5/3/2023
1.0.13 343 3/9/2023
1.0.12 311 3/8/2023
1.0.11 296 3/6/2023
1.0.10 473 11/22/2022
1.0.9 419 11/16/2022
1.0.8 423 11/12/2022
1.0.7 527 10/20/2022
1.0.6 582 8/16/2022
1.0.5 508 8/11/2022
1.0.4 516 8/9/2022
1.0.3 509 8/2/2022
1.0.2 550 6/9/2022
1.0.1 537 6/9/2022
1.0.0 536 6/9/2022