Skip to content

Instantly share code, notes, and snippets.

@Regenhardt
Created June 18, 2021 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Regenhardt/734ae4dbc2a0ea73752c1d13493a9c9b to your computer and use it in GitHub Desktop.
Save Regenhardt/734ae4dbc2a0ea73752c1d13493a9c9b to your computer and use it in GitHub Desktop.
private const string StandardConnectionString =
"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\me\\source\\repos\\teambuilder\\TeamBuilderServer\\TeamBuilderDB.mdf;Integrated Security=True;MultipleActiveResultSets=True;";
public static IServiceCollection AddDatabase(this IServiceCollection services, string? connectionString = null)
{
services.AddDbContextPool<Entities>(options =>
{
options.EnableDetailedErrors();
options.UseSqlServer(connectionString ?? StandardConnectionString);
});
services.AddTransient<IAccountRepository, AccountDbAccess>();
services.AddTransient<ITeamRepository, TeamDbAccess>();
services.AddSingleton<ICryptoService, CryptoService>();
return services;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment