Skip to content

Commit

Permalink
Disable AOT, refactor Program.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Nov 26, 2023
1 parent 86bb85e commit bc33295
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 197 deletions.
1 change: 0 additions & 1 deletion BotNet/BotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<ServerGarbageCollection>true</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
Expand Down
142 changes: 80 additions & 62 deletions BotNet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BotNet;
using BotNet.Bot;
using BotNet.Bot;
using BotNet.Services.BMKG;
using BotNet.Services.Brainfuck;
using BotNet.Services.ClearScript;
Expand All @@ -9,10 +8,11 @@
using BotNet.Services.GoogleMap;
using BotNet.Services.Hosting;
using BotNet.Services.ImageConverter;
using BotNet.Services.Meme;
using BotNet.Services.OpenAI;
using BotNet.Services.OpenGraph;
using BotNet.Services.Piston;
using BotNet.Services.Pesto;
using BotNet.Services.Piston;
using BotNet.Services.Preview;
using BotNet.Services.ProgrammerHumor;
using BotNet.Services.Stability;
Expand All @@ -22,71 +22,89 @@
using BotNet.Services.Tokopedia;
using BotNet.Services.Typography;
using BotNet.Services.Weather;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans.Hosting;
using BotNet.Services.Meme;

Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.ConfigureAppConfiguration((hostBuilderContext, configurationBuilder) => {
configurationBuilder
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{hostBuilderContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddKeyPerFile("/run/secrets", optional: true, reloadOnChange: true)
.AddEnvironmentVariables("ASPNETCORE_")
.AddUserSecrets<BotService>(optional: true, reloadOnChange: true);
})
.ConfigureServices((hostBuilderContext, services) => {
IConfiguration configuration = hostBuilderContext.Configuration;
WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);

// HTTPS
builder.WebHost.UseKestrelHttpsConfiguration();

// Configuration sources
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddKeyPerFile("/run/secrets", optional: true, reloadOnChange: true)
.AddEnvironmentVariables("ASPNETCORE_")
.AddUserSecrets<BotService>(optional: true, reloadOnChange: true);

// DI Services
builder.Services.Configure<HostingOptions>(builder.Configuration.GetSection("HostingOptions"));
builder.Services.Configure<TenorOptions>(builder.Configuration.GetSection("TenorOptions"));
builder.Services.Configure<V8Options>(builder.Configuration.GetSection("V8Options"));
builder.Services.Configure<PistonOptions>(builder.Configuration.GetSection("PistonOptions"));
builder.Services.Configure<PestoOptions>(builder.Configuration.GetSection("PestoOptions"));
builder.Services.Configure<OpenAIOptions>(builder.Configuration.GetSection("OpenAIOptions"));
builder.Services.Configure<StabilityOptions>(builder.Configuration.GetSection("StabilityOptions"));
builder.Services.Configure<GoogleMapOptions>(builder.Configuration.GetSection("GoogleMapOptions"));
builder.Services.Configure<WeatherOptions>(builder.Configuration.GetSection("WeatherOptions"));
builder.Services.AddHttpClient();
builder.Services.AddTenorClient();
builder.Services.AddFontService();
builder.Services.AddColorCardRenderer();
builder.Services.AddOpenGraph();
builder.Services.AddImageConverter();
builder.Services.AddBrainfuckTranspiler();
builder.Services.AddV8Evaluator();
builder.Services.AddPistonClient();
builder.Services.AddPestoClient();
builder.Services.AddOpenAIClient();
builder.Services.AddProgrammerHumorScraper();
builder.Services.AddTiktokServices();
builder.Services.AddCSharpEvaluator();
builder.Services.AddThisXDoesNotExist();
builder.Services.AddCraiyonClient();
builder.Services.AddStabilityClient();
builder.Services.AddTokopediaServices();
builder.Services.AddGoogleMaps();
builder.Services.AddWeatherService();
builder.Services.AddBMKG();
builder.Services.AddPreviewServices();
builder.Services.AddMemeGenerator();

// Hosted Services
builder.Services.Configure<BotOptions>(builder.Configuration.GetSection("BotOptions"));
builder.Services.AddSingleton<BotService>();
builder.Services.AddHostedService<BotService>();

// Telegram Bot
builder.Services.AddTelegramBot(botToken: builder.Configuration["BotOptions:AccessToken"]!);

// Localhost Orleans
builder.Host.UseOrleans((hostBuilderContext, siloBuilder) => {
siloBuilder.UseLocalhostClustering();
});

// Web
builder.Services.AddControllersWithViews().AddNewtonsoftJson();
builder.Services.AddResponseCaching();
builder.Services.AddResponseCompression();

WebApplication app = builder.Build();

// DI Services
services.Configure<HostingOptions>(configuration.GetSection("HostingOptions"));
services.Configure<TenorOptions>(configuration.GetSection("TenorOptions"));
services.Configure<V8Options>(configuration.GetSection("V8Options"));
services.Configure<PistonOptions>(configuration.GetSection("PistonOptions"));
services.Configure<PestoOptions>(configuration.GetSection("PestoOptions"));
services.Configure<OpenAIOptions>(configuration.GetSection("OpenAIOptions"));
services.Configure<StabilityOptions>(configuration.GetSection("StabilityOptions"));
services.Configure<GoogleMapOptions>(configuration.GetSection("GoogleMapOptions"));
services.Configure<WeatherOptions>(configuration.GetSection("WeatherOptions"));
services.AddHttpClient();
services.AddTenorClient();
services.AddFontService();
services.AddColorCardRenderer();
services.AddOpenGraph();
services.AddImageConverter();
services.AddBrainfuckTranspiler();
services.AddV8Evaluator();
services.AddPistonClient();
services.AddPestoClient();
services.AddOpenAIClient();
services.AddProgrammerHumorScraper();
services.AddTiktokServices();
services.AddCSharpEvaluator();
services.AddThisXDoesNotExist();
services.AddCraiyonClient();
services.AddStabilityClient();
services.AddTokopediaServices();
services.AddGoogleMaps();
services.AddWeatherService();
services.AddBMKG();
services.AddPreviewServices();
services.AddMemeGenerator();
if (app.Environment.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} else {
app.UseHsts();
}

// Hosted Services
services.Configure<BotOptions>(configuration.GetSection("BotOptions"));
services.AddSingleton<BotService>();
services.AddHostedService<BotService>();
app.UseHttpsRedirection();
app.UseRouting();
app.UseResponseCaching();
app.UseResponseCompression();
app.MapControllers();

// Telegram Bot
services.AddTelegramBot(botToken: configuration["BotOptions:AccessToken"]!);
})
.UseOrleans((hostBuilderContext, siloBuilder) => {
siloBuilder
.UseLocalhostClustering();
})
.Build()
.Run();
app.Run();
66 changes: 0 additions & 66 deletions BotNet/Properties/ServiceDependencies/local/appInsights.arm.json

This file was deleted.

2 changes: 1 addition & 1 deletion BotNet/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"dotnetRunMessages": "true"
"dotnetRunMessages": true
},
"Docker": {
"commandName": "Docker",
Expand Down
11 changes: 0 additions & 11 deletions BotNet/Properties/serviceDependencies.json

This file was deleted.

13 changes: 0 additions & 13 deletions BotNet/Properties/serviceDependencies.local.json

This file was deleted.

43 changes: 0 additions & 43 deletions BotNet/Startup.cs

This file was deleted.

0 comments on commit bc33295

Please sign in to comment.