Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Created July 9, 2024 12:40
Show Gist options
  • Save ChrisMoney/174e72cad4d5df3e9bda9cb743d008ac to your computer and use it in GitHub Desktop.
Save ChrisMoney/174e72cad4d5df3e9bda9cb743d008ac to your computer and use it in GitHub Desktop.
Entity Framework DBContext Injection occurs at application entry point, typically Main.cs
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using AdamsTaxAPI.Data;
using AdamsTaxAPI.Data.MagentoServiceCalls;
using AdamsTaxAPI.Models;
using AdamsTaxAPI.Controllers;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using Aczure.Extensions.AspNetCore.Configuration.Secrets;
using Reni.SshNet.Sftp;
using System.Text.Json.Serialization;
using AdamsTaxAPI.Data.Helpers;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<ApiDataContext>(options =>
options.UseSqlServer(builder.Configuration.
GetConnectionString("ConnectionString"),
o => o.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery)
.CommandTimeout((int)TimeSpan.FromMinutes(Utilities.SqlCommandTimeout()).TotalSeconds)
.EnableRetryOnFailure(Utilities.SqlRetryCount(), TimeSpan.FromSeconds(Utilities.SqlRetryTimeout()), null))
.ConfigureWarnings(warnings => warnings.Ignore(CoreEventId.RowLimitingOperationWithoutOrderByWarning))
);
builder.Services.AddDbContext<Historic2022Context>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("Historic2022")));
builder.Services.AddDbContext<Historic2021Context>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("Historic2021")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment