Skip to content

Commit ad22a61

Browse files
committed
switched to minimal api
1 parent 9dcf37a commit ad22a61

File tree

3 files changed

+71
-168
lines changed

3 files changed

+71
-168
lines changed

YAF.SampleApp/Program.cs

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,77 @@
2222
* under the License.
2323
*/
2424

25+
using Autofac;
26+
using Autofac.Extensions.DependencyInjection;
27+
2528
using YAF.Core.Extensions;
29+
using YAF.Core.Hubs;
30+
using YAF.Core.Middleware;
31+
using YAF.RazorPages;
32+
using YAF.UI.Chat;
33+
34+
var builder = WebApplication.CreateBuilder(args);
2635

27-
namespace YAF.SampleApp;
36+
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
2837

29-
/// <summary>
30-
/// Class Program.
31-
/// </summary>
32-
public class Program
38+
builder.Host.ConfigureYafLogging();
39+
40+
builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
3341
{
34-
/// <summary>
35-
/// Defines the entry point of the application.
36-
/// </summary>
37-
/// <param name="args">
38-
/// The arguments.
39-
/// </param>
40-
/// <returns>
41-
/// The <see cref="Task"/>.
42-
/// </returns>
43-
public static Task Main(string[] args)
44-
{
45-
var host = Host.CreateDefaultBuilder(args).UseAutofacServiceProviderFactory()
46-
.ConfigureYafLogging()
47-
.ConfigureWebHostDefaults(webHostBuilder =>
48-
webHostBuilder.UseStartup<Startup>()).Build();
49-
50-
return host.RunAsync();
51-
}
52-
}
42+
containerBuilder.RegisterYafModules();
43+
});
44+
45+
builder.Services.AddRazorPages(options =>
46+
{
47+
options.Conventions.AddAreaPageRoute("Forums", "/SiteMap", "/Sitemap.xml");
48+
}).AddYafRazorPages(builder.Environment);
49+
50+
builder.Services.AddYafCore(builder.Configuration);
51+
52+
// only needed for blazor
53+
builder.Services.AddServerSideBlazor();
54+
55+
var app = builder.Build();
56+
57+
if (app.Environment.IsDevelopment())
58+
{
59+
app.UseDeveloperExceptionPage();
60+
}
61+
else
62+
{
63+
app.UseExceptionHandler("/Forums/Error");
64+
65+
app.UseHsts();
66+
}
67+
68+
app.RegisterAutofac();
69+
70+
app.UseAntiXssMiddleware();
71+
72+
app.UseStaticFiles();
73+
74+
app.UseSession();
75+
76+
app.UseYafCore(BoardContext.Current.ServiceLocator, app.Environment);
77+
78+
app.UseRobotsTxt(app.Environment);
79+
80+
app.MapRazorPages();
81+
82+
// only needed for blazor
83+
app.MapBlazorHub();
84+
app.MapFallbackToPage("/_Host");
85+
86+
app.MapAreaControllerRoute(
87+
name: "default",
88+
areaName: "Forums",
89+
pattern: "{controller=Home}/{action=Index}/{id?}");
90+
91+
app.MapControllers();
92+
93+
app.MapHub<NotificationHub>("/NotificationHub");
94+
app.MapHub<ChatHub>("/ChatHub");
95+
96+
app.MapHub<AllChatHub>("/AllChatHub");
97+
98+
await app.RunAsync();

YAF.SampleApp/Startup.cs

Lines changed: 0 additions & 144 deletions
This file was deleted.

YAF.SampleApp/YAF.SampleApp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<Content Remove="C:\Users\iherb\.nuget\packages\yafnet.razorpages\4.0.0\contentFiles\any\net9.0\package-lock.json" />
1011
<Content Remove="C:\Users\iherb\.nuget\packages\yafnet.ui.chat\4.0.0-rc02\contentFiles\any\net8.0\libman.json" />
1112
</ItemGroup>
1213

0 commit comments

Comments
 (0)