Skip to content

Commit bcfebb3

Browse files
committed
Cleaning
1 parent 795e651 commit bcfebb3

1 file changed

Lines changed: 49 additions & 49 deletions

File tree

Extensions.cs

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.AspNetCore.Mvc.Formatters;
3+
using Microsoft.Extensions.DependencyInjection;
34
using System.Text;
45
using System.Text.Json;
5-
using Telegram.Bot;
66
using Telegram.Bot.Requests.Abstractions;
77
using Telegram.Bot.Types;
88

9-
namespace Microsoft.Extensions.DependencyInjection
9+
namespace Telegram.Bot.AspNetCore
1010
{
11-
/// <summary>Helpers for WebApp service configuration</summary>
12-
public static class TelegramBotConfigureExtensions
13-
{
14-
/// <summary>Configure ASP.NET MVC Json (de)serialization for Telegram.Bot types</summary>
15-
/// <param name="services">The IServiceCollection to add the services to.</param>
16-
public static IServiceCollection ConfigureTelegramBotMvc(this IServiceCollection services)
17-
=> services.Configure<MvcOptions>(options =>
18-
{
19-
options.InputFormatters.Insert(0, _inputFormatter);
20-
options.OutputFormatters.Insert(0, _outputFormatter);
21-
});
22-
23-
private static readonly TelegramBotInputFormatter _inputFormatter = new();
11+
/// <summary>Helpers for WebApp service configuration</summary>
12+
public static class Extensions
13+
{
14+
/// <summary>Configure ASP.NET MVC Json (de)serialization for Telegram.Bot types</summary>
15+
/// <param name="services">The IServiceCollection to add the services to.</param>
16+
public static IServiceCollection ConfigureTelegramBotMvc(this IServiceCollection services)
17+
=> services.Configure<MvcOptions>(options =>
18+
{
19+
options.InputFormatters.Insert(0, _inputFormatter);
20+
options.OutputFormatters.Insert(0, _outputFormatter);
21+
});
22+
23+
private static readonly TelegramBotInputFormatter _inputFormatter = new();
2424
private static readonly TelegramBotOutputFormatter _outputFormatter = new();
2525

26-
private class TelegramBotInputFormatter : TextInputFormatter
27-
{
28-
public TelegramBotInputFormatter()
29-
{
30-
SupportedEncodings.Add(Encoding.UTF8);
31-
SupportedMediaTypes.Add("application/json");
32-
}
33-
34-
protected override bool CanReadType(Type type) => type == typeof(Update);
35-
36-
public sealed override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
37-
{
38-
var model = await JsonSerializer.DeserializeAsync(context.HttpContext.Request.Body, context.ModelType, JsonBotAPI.Options, context.HttpContext.RequestAborted);
39-
return await InputFormatterResult.SuccessAsync(model);
40-
}
41-
}
42-
43-
private class TelegramBotOutputFormatter : TextOutputFormatter
44-
{
45-
public TelegramBotOutputFormatter()
46-
{
47-
SupportedEncodings.Add(Encoding.UTF8);
48-
SupportedMediaTypes.Add("application/json");
49-
}
50-
51-
protected override bool CanWriteType(Type? type) => typeof(IRequest).IsAssignableFrom(type);
52-
53-
public sealed override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
54-
{
55-
var stream = context.HttpContext.Response.Body;
56-
await JsonSerializer.SerializeAsync(stream, context.Object, JsonBotAPI.Options, context.HttpContext.RequestAborted);
57-
}
58-
}
59-
}
26+
private class TelegramBotInputFormatter : TextInputFormatter
27+
{
28+
public TelegramBotInputFormatter()
29+
{
30+
SupportedEncodings.Add(Encoding.UTF8);
31+
SupportedMediaTypes.Add("application/json");
32+
}
33+
34+
protected override bool CanReadType(Type type) => type == typeof(Update);
35+
36+
public sealed override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
37+
{
38+
var model = await JsonSerializer.DeserializeAsync(context.HttpContext.Request.Body, context.ModelType, JsonBotAPI.Options, context.HttpContext.RequestAborted);
39+
return await InputFormatterResult.SuccessAsync(model);
40+
}
41+
}
42+
43+
private class TelegramBotOutputFormatter : TextOutputFormatter
44+
{
45+
public TelegramBotOutputFormatter()
46+
{
47+
SupportedEncodings.Add(Encoding.UTF8);
48+
SupportedMediaTypes.Add("application/json");
49+
}
50+
51+
protected override bool CanWriteType(Type? type) => typeof(IRequest).IsAssignableFrom(type);
52+
53+
public sealed override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
54+
{
55+
var stream = context.HttpContext.Response.Body;
56+
await JsonSerializer.SerializeAsync(stream, context.Object, JsonBotAPI.Options, context.HttpContext.RequestAborted);
57+
}
58+
}
59+
}
6060
}

0 commit comments

Comments
 (0)