Skip to main content

Introduction

Alert.CA.Infrastructure

A shared .NET 8 class library published as a NuGet package (AlertCAInfrastructure), providing IServiceCollection extension methods, repository abstractions, service implementations, data models, and configuration options for Azure services. This package is the foundational data and service layer for the Alert.CA solution — consuming applications reference it via a private NuGet feed and inject the services they need into their dependency injection containers.

Architecture Overview

Tech Stack

  • .NET 8: Target framework
  • Azure Cosmos DB: NoSQL database for camera, user, and device state
  • Azure SQL Database: Relational database for locations, alerts, notifications, audit, and feature flags
  • Azure Blob Storage: Image, video, location file, and device data storage
  • Azure Table Storage: Image and video metadata with index tables
  • Azure Queue Storage: Asynchronous message processing (image caching, deletion, orchestration)
  • Azure Communication Services: Email and SMS integration
  • Microsoft Graph: Entra ID user and directory operations
  • Azure Key Vault: Encryption keys and secrets management
  • Azure App Configuration: Centralized configuration with Key Vault references
  • Azure Identity: DefaultAzureCredential for unified authentication
  • Dapper: Micro-ORM for SQL Server data access
  • NetTopologySuite / ProjNET: Geospatial geometry and coordinate system transformations

Solution Structure

  • Alert.CA.Infrastructure: Main class library — the NuGet package consumers install
  • Alert.CA.Infrastructure.Test: xUnit test project (Moq, NetTopologySuite)
  • Alert.CA.Infrastructure.TroubleshootAPI: ASP.NET Core diagnostic API with 22 controllers for testing infrastructure services locally
  • Alert.CA.Infrastructure.Data: SQL Server database project (DACPAC deployment with 26 tables, 49 stored procedures, and user-defined types)
  • Alert.CA.Infrastructure.GeometryImport: Geometry import utility

Package Architecture

DirectoryPurpose
Extensions/ServiceCollectionExtensions.cs — all DI registration extension methods
Models/Data models organized by storage backend (Cosmos, SQL, Table Storage, Condor AI, DTOs)
Repositories/Repository abstractions and implementations by storage backend
Services/Business logic: Alerts, Audit, Communication (Email, SMS, Phone), Graph, Location, Notification, Security, Queue
Options/25 typed options classes for configuration binding
Utilities/Constants, LINQ helpers, MIME types, query string utilities

Getting Started

Prerequisites

  • .NET 8 SDK
  • Visual Studio 2022+ (or Rider / VS Code with C# Dev Kit)
  • Access to the Alert.CA Azure DevOps organization
  • Azure account with membership in the Insight-AlertCA user group

1. Add the NuGet Source

Create a nuget.config file in the solution root:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="Alert.CA.Common" value="https://pkgs.dev.azure.com/cardinalsolutions/4f9f6476-856e-468b-8039-5f1adb64aa9c/_packaging/Alert.CA.Common/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>

Verify the source appears in Tools > Options > NuGet Package Manager > Package Sources.

2. Install the Package

dotnet add package AlertCAInfrastructure

3. Connect to Azure App Configuration

In appsettings.Development.json or local.settings.json:

{
"Endpoints": {
"AppConfig": "https://appcs-wfca-ca-config-alertca-[ENV]-001.azconfig.io"
}
}

In Program.cs:

var azureConfig = (IConfiguration)builder.Configuration.AddAzureAppConfiguration(options =>
options.Connect(
new Uri(builder.Configuration["Endpoints:AppConfig"]!),
new DefaultAzureCredential()));

4. Register Services

Call the extension methods for the services your application needs in Program.cs:

using Alert.CA.Infrastructure.Extensions;

// Core data services
builder.Services.AddAlertCACosmosDbServices(azureConfig);
builder.Services.AddAlertCAStorageServices(azureConfig);
builder.Services.AddAlertCASQLDatabaseServices(azureConfig);

// Integration services
builder.Services.AddCommunicationServices(azureConfig);
builder.Services.AddGraphServices(azureConfig);

// Application services
builder.Services.AddAuditService();
builder.Services.AddApiKeyValidator(azureConfig);
builder.Services.AddEncryptionService(azureConfig, credential);
builder.Services.AddAlertService(azureConfig);
builder.Services.AddNotificationService(azureConfig);
builder.Services.AddJWTService(azureConfig);

// Options-only
builder.Services.AddAlertCAAppConfigurationOptions(azureConfig);
builder.Services.AddAlertCAArchiveOptions(azureConfig);

You only need to register what your application uses. See the data engine pages for details on what each method registers.

5. Azure Authentication

The package uses DefaultAzureCredential for Azure authentication. For local development:

  1. In Visual Studio: Tools > Options > Azure Service Authentication — sign in with your [First].[Last]@wfca.com account
  2. Ensure your account is a member of the Insight-AlertCA user group

DefaultAzureCredential uses VisualStudioCredential locally and ManagedIdentityCredential in deployed environments.

Deployment

NuGet Package

The package is automatically generated on build (GeneratePackageOnBuild). The CI/CD pipeline builds, versions, and publishes AlertCAInfrastructure to the Alert.CA.Common Azure DevOps Artifacts feed. Consuming applications update their package version to pull changes.

SQL Database

The Alert.CA.Infrastructure.Data project produces a DACPAC deployed to Azure SQL Database via the pipeline. It contains all table schemas, stored procedures, user-defined types, and deployment scripts.

Pipeline Stages

  1. Version — semantic version bump
  2. Build — compile, test, and package
  3. Publish — push NuGet package to feed and DACPAC to artifacts
  4. Deploy (Dev) — deploy SQL database changes to development
  5. Deploy (UAT) — deploy SQL database changes to UAT