organize - behaver is not a behavior, only one use of connection string

This commit is contained in:
Adam R Grey 2024-04-05 22:15:59 -04:00
parent 6d181e2b68
commit ef31418166
4 changed files with 10 additions and 8 deletions

View File

@ -1,5 +1,6 @@
namespace vassago.Behavior;
namespace vassago;
#pragma warning disable 4014 //the "not awaited" error
using vassago.Behavior;
using vassago.Models;
using System;
using System.Linq;
@ -12,18 +13,18 @@ public class Behaver
{
private List<Account> SelfAccounts { get; set; } = new List<Account>();
private User SelfUser { get; set; }
public static List<Behavior> Behaviors { get; private set; } = new List<Behavior>();
public static List<vassago.Behavior.Behavior> Behaviors { get; private set; } = new List<vassago.Behavior.Behavior>();
internal Behaver()
{
var subtypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(domainAssembly => domainAssembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(Behavior)) && !type.IsAbstract &&
.Where(type => type.IsSubclassOf(typeof(vassago.Behavior.Behavior)) && !type.IsAbstract &&
type.GetCustomAttributes(typeof(StaticPlzAttribute),false)?.Any() == true)
.ToList();
foreach (var subtype in subtypes)
{
Behaviors.Add((Behavior)Activator.CreateInstance(subtype));
Behaviors.Add((vassago.Behavior.Behavior)Activator.CreateInstance(subtype));
}
}
static Behaver() { }

View File

@ -44,7 +44,7 @@ namespace vassago
public Task StopAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
return null;
}
}
}

View File

@ -17,6 +17,8 @@ public class ChattingContext : DbContext
public ChattingContext(DbContextOptions<ChattingContext> options) : base(options) { }
public ChattingContext() : base() { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseNpgsql(Shared.DBConnectionString)
{
optionsBuilder.UseNpgsql(Shared.DBConnectionString)
.EnableSensitiveDataLogging(true); //who the fuck is looking at log output but not allowed to see it? this should be on by default.
}
}

View File

@ -6,8 +6,7 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
builder.Services.AddDbContext<ChattingContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("ChattingContext") ));
builder.Services.AddDbContext<ChattingContext>();
var app = builder.Build();