-
Notifications
You must be signed in to change notification settings - Fork 0
/
IServiceCollectionExtension.cs
38 lines (36 loc) · 1.36 KB
/
IServiceCollectionExtension.cs
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
using Blazor.FileReader;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using System.Net.Http;
namespace EmojiPicker
{
public static class IServiceCollectionExtension
{
public static IServiceCollection AddEmojiPicker(this IServiceCollection services)
{
// Filereader - Image uploads etc.
services.AddFileReaderService();
services.AddServerSideBlazor().AddHubOptions(opts =>
{
opts.MaximumReceiveMessageSize = 10 * 1024 * 1024; // 10MB
});
// Server Side Blazor doesn't register HttpClient by default
if (!services.Any(x => x.ServiceType == typeof(HttpClient)))
{
// Setup HttpClient for server side in a client side compatible fashion
services.AddScoped<HttpClient>(s =>
{
// Creating the URI helper needs to wait until the JS Runtime is initialized, so defer it.
var uriHelper = s.GetRequiredService<NavigationManager>();
return new HttpClient
{
BaseAddress = new Uri(uriHelper.BaseUri)
};
});
}
return services;
}
}
}