SeemGen/Program.cs

136 lines
4.9 KiB
C#

using BLAIzor.Components;
using BLAIzor.Components.Partials;
using BLAIzor.Data;
using BLAIzor.Helpers;
using BLAIzor.Interfaces;
using BLAIzor.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.EntityFrameworkCore;
using Radzen;
using Sidio.Sitemap.AspNetCore;
using Sidio.Sitemap.Blazor;
using Sidio.Sitemap.Core.Services;
using System;
using System.Net.Http.Headers;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
builder.WebHost.UseWebRoot("wwwroot");
// Add services to the container.
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
// Add Identity services
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
//builder.Services.AddBlazorServerOptions(options =>
//{
// options.MaxBufferSize = 50 * 1024 * 1024; // Set to 50 MB
//});
builder.Services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = 50 * 1024 * 1024;
});
var env = builder.Environment; // This is IWebHostEnvironment
if (env.IsProduction())
{
// do production-specific setup
}
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddRadzenComponents();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
// Required for scoped injection (used in pages/services)
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
// Required for factory-based logging or background usage
builder.Services.AddDbContextFactory<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString), ServiceLifetime.Scoped);
builder.Services.AddHttpClient();
builder.Services.AddScoped<ISimpleLogger, SimpleLogger>();
builder.Services.AddScoped<AIService>();
//builder.Services.AddSingleton<ContentService>();
builder.Services.AddScoped<ScopedContentService>();
builder.Services.AddScoped<QDrantService>();
builder.Services.AddScoped<OpenAIEmbeddingService>();
builder.Services.AddScoped<LocalEmbeddingService>();
builder.Services.AddScoped<HtmlSnippetProcessor>();
builder.Services
.AddHttpContextAccessor()
.AddDefaultSitemapServices<HttpContextBaseUrlProvider>();
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthenticationStateProvider>();
builder.Services.AddScoped<CustomAuthenticationStateProvider>();
builder.Services.Configure<SmtpSettings>(builder.Configuration.GetSection("Smtp"));
builder.Services.AddTransient<IEmailSender, EmailService>();
builder.Services.AddScoped<ContentEditorService>();
builder.Services.AddScoped<ContentEditorAIService>();
builder.Services.AddScoped<CssTemplateService>();
builder.Services.AddScoped<DesignTemplateService>();
builder.Services.AddScoped<OpenAIApiService>();
builder.Services.AddScoped<DeepSeekApiService>();
builder.Services.AddScoped<OpenAiRealtimeService>();
builder.Services.AddScoped<CerebrasAPIService>();
builder.Services.AddScoped<KimiApiService>();
builder.Services.AddScoped<CssInjectorService>();
builder.Services.AddScoped<LocalVectorSearchService>();
builder.Services.AddScoped<WebsiteContentLoaderService>();
builder.Services.AddScoped<CacheService>();
builder.Services.AddSingleton<CreateSiteWizard>();
builder.Services.AddScoped<WhisperTranscriptionService>();
builder.Services.AddScoped<IBrightDataService, BrightDataService>();
builder.Services.AddHttpClient<ReplicateService>(client =>
{
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", "r8_MUApXYIE5mRjxqy20tsGLehWBJkCzNj0Cwvrh");
});
builder.Services.AddHostedService<TempFileCleanupService>();
builder.Services.AddServerSideBlazor().AddCircuitOptions(options => options.DetailedErrors = true).AddHubOptions(options =>
{
options.MaximumReceiveMessageSize = 1024000; // e.g. 100 KB
}); ;
builder.Services.AddSignalR(hubOptions => {
hubOptions.MaximumReceiveMessageSize = 10 * 1024 * 1024; });
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorPages();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.UseMiddleware<SubdomainMiddleware>();
app.UseSitemap();
app.Run();