# Google.Cloud.Spanner.Data - Class ServiceCollectionExtensions (5.13.0-beta07)

5.13.0-beta07 5.13.0-beta06 5.12.0 (latest) 5.11.0 5.10.0 5.9.0 5.8.0 5.7.0 5.6.0 5.5.0 5.4.0 5.3.0 5.2.0 5.1.0 5.0.0 4.6.0 4.5.0 4.4.0 4.3.0 4.2.0 4.1.0 4.0.0 3.15.1 3.14.0 3.13.0 3.12.0 3.11.0 3.10.0 3.9.0 3.8.0 3.7.0 3.6.0 3.5.0

    public static class ServiceCollectionExtensions

Reference documentation and code samples for the Google.Cloud.Spanner.Data class ServiceCollectionExtensions.

Provides extension methods to configure dependency injection with Spanner.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> ServiceCollectionExtensions

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Microsoft.Extensions.DependencyInjection](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.Data/latest/Microsoft.Extensions.DependencyInjection)

## Assembly

Google.Cloud.Spanner.Data.dll

## Methods

### AddSpannerConnection(IServiceCollection, string)

    public static IServiceCollection AddSpannerConnection(this IServiceCollection services, string connectionStringName)

Adds a transient service providing a [SpannerConnection](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.Data/latest/Google.Cloud.Spanner.Data.SpannerConnection) using the ConnectionStrings
section of the configuration. If the container providers a [ChannelCredentials](https://cloud.google.com/dotnet/docs/reference/Grpc.Core/latest/Grpc.Core.ChannelCredentials.html) or
[GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential.html), this will be used for the connection (with [ChannelCredentials](https://cloud.google.com/dotnet/docs/reference/Grpc.Core/latest/Grpc.Core.ChannelCredentials.html) taking precedence).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `services` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` The service collection to add the transient dependency to. |
| `connectionStringName` | `https://learn.microsoft.com/dotnet/api/system.string` The name of the the connection string within the ConnectionStrings section of the configuration. Must not be null or empty. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` | The same service collection (`services`), for method chaining. |