Updated lots of stuff, got multi scrape working, need to test not-nullable chapter novel ids with our current model, now supports sqlite and postgres concurrently (and easy add more), need to get it deployed/do auth
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using DBConnection.Contexts;
|
||||
using DBConnection.Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -15,11 +16,22 @@ public static class BuilderExtensions
|
||||
/// <param name="config">configuration</param>
|
||||
public static void AddDbServices(this IServiceCollection collection, IConfiguration config)
|
||||
{
|
||||
string dbConnectionString = config.GetConnectionString("DefaultConnection");
|
||||
collection.AddDbContext<AppDbContext>(opt =>
|
||||
{
|
||||
opt.UseSqlite(dbConnectionString);
|
||||
});
|
||||
// Add appropriate DbContext
|
||||
// Contexts are linked to providers by trimming the 'AppDbContext' portion of their name.
|
||||
// So 'PostgresSqlAppDbContext' is selected with provider 'PostgresSql'
|
||||
var providerTypes = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => (t.Namespace?.Contains(nameof(Contexts)) ?? false) && typeof(AppDbContext).IsAssignableFrom(t) && !t.IsAbstract && t.Name.EndsWith(nameof(AppDbContext)));
|
||||
var providers = providerTypes.ToDictionary(t => t.Name.Replace(nameof(AppDbContext), ""), t => t);
|
||||
var selectedProvider = config["DatabaseProvider"];
|
||||
|
||||
//add dboptions
|
||||
collection.AddSingleton(new DbContextOptions<AppDbContext>());
|
||||
collection.AddSingleton<DbContextOptions>(p => p.GetRequiredService<DbContextOptions<AppDbContext>>());
|
||||
|
||||
// add our provider dbcontext
|
||||
collection.AddScoped(typeof(AppDbContext), providers[selectedProvider]);
|
||||
|
||||
// Add db repositories
|
||||
Type[] repositories = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => t.IsClass && !t.IsAbstract && (t.Namespace?.Contains(nameof(DBConnection.Repositories)) ?? false) && typeof(IRepository).IsAssignableFrom(t)).ToArray();
|
||||
foreach (var repo in repositories)
|
||||
|
||||
Reference in New Issue
Block a user