-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathServiceExtensions.cs
More file actions
85 lines (71 loc) · 2.91 KB
/
ServiceExtensions.cs
File metadata and controls
85 lines (71 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Threading.RateLimiting;
using Blazorise;
using Blazorise.Bootstrap5;
using LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Services;
using LinkDotNet.Blog.Web.Features.Admin.Sitemap.Services;
using LinkDotNet.Blog.Web.Features.Bookmarks;
using LinkDotNet.Blog.Web.Features.Services;
using LinkDotNet.Blog.Web.Features.Services.Tags;
using LinkDotNet.Blog.Web.RegistrationExtensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace LinkDotNet.Blog.Web;
public static class ServiceExtensions
{
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
{
services.AddSingleton(TimeProvider.System);
services.AddScoped<ILocalStorageService, LocalStorageService>();
services.AddScoped<ISortOrderCalculator, SortOrderCalculator>();
services.AddScoped<IUserRecordService, UserRecordService>();
services.AddScoped<IBookmarkService, BookmarkService>();
services.AddScoped<ISitemapService, SitemapService>();
services.AddScoped<IXmlWriter, XmlWriter>();
services.AddScoped<IFileProcessor, FileProcessor>();
services.AddScoped<ICurrentUserService, CurrentUserService>();
services.AddScoped<ITagQueryService, TagQueryService>();
services.AddSingleton<CacheService>();
services.AddSingleton<ICacheInvalidator>(s => s.GetRequiredService<CacheService>());
services.AddBackgroundServices();
return services;
}
public static IServiceCollection AddRateLimiting(this IServiceCollection services)
{
services.AddRateLimiter(options =>
{
options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
options.AddPolicy<string>("ip", httpContext =>
RateLimitPartition.GetFixedWindowLimiter(
httpContext.Connection.RemoteIpAddress?.ToString() ?? string.Empty,
_ => new FixedWindowRateLimiterOptions { PermitLimit = 15, Window = TimeSpan.FromMinutes(1) })
);
});
return services;
}
public static IServiceCollection AddBlazoriseWithBootstrap(this IServiceCollection services)
{
services
.AddBlazorise()
.AddBootstrap5Providers();
return services;
}
public static IServiceCollection AddHostingServices(this IServiceCollection services)
{
services.AddRazorPages();
services.AddRazorComponents()
.AddInteractiveServerComponents();
services.AddSignalR(options =>
{
options.MaximumReceiveMessageSize = 1024 * 1024;
});
return services;
}
public static IServiceCollection AddHealthCheckSetup(this IServiceCollection services)
{
services.AddHealthChecks()
.AddCheck<DatabaseHealthCheck>("Database");
return services;
}
}