Code cleanup

This commit is contained in:
Archi
2021-11-10 21:47:42 +01:00
parent 1e6ab11d9f
commit d46e532458
9 changed files with 99 additions and 82 deletions

View File

@@ -166,7 +166,7 @@ internal sealed class Startup {
// Finally register proper API endpoints once we're done with routing
#if NETFRAMEWORK
app.UseMvcWithDefaultRoute();
app.UseMvcWithDefaultRoute();
#else
app.UseEndpoints(static endpoints => endpoints.MapControllers());
#endif
@@ -345,14 +345,14 @@ internal sealed class Startup {
mvc.AddControllersAsServices();
#if NETFRAMEWORK
// Use latest compatibility version for MVC
mvc.SetCompatibilityVersion(CompatibilityVersion.Latest);
// Use latest compatibility version for MVC
mvc.SetCompatibilityVersion(CompatibilityVersion.Latest);
// Add standard formatters
mvc.AddFormatterMappings();
// Add standard formatters
mvc.AddFormatterMappings();
// Add API explorer for swagger
mvc.AddApiExplorer();
// Add API explorer for swagger
mvc.AddApiExplorer();
#endif
mvc.AddNewtonsoftJson(
@@ -365,8 +365,8 @@ internal sealed class Startup {
}
#if NETFRAMEWORK
// .NET Framework serializes Version as object by default, serialize it as string just like .NET Core
options.SerializerSettings.Converters.Add(new VersionConverter());
// .NET Framework serializes Version as object by default, serialize it as string just like .NET Core
options.SerializerSettings.Converters.Add(new VersionConverter());
#endif
}
);

View File

@@ -36,38 +36,42 @@ namespace ArchiSteamFarm.IPC;
internal static class WebUtilities {
#if NETFRAMEWORK
internal static IMvcCoreBuilder AddControllers(this IServiceCollection services) {
if (services == null) {
throw new ArgumentNullException(nameof(services));
}
return services.AddMvcCore();
internal static IMvcCoreBuilder AddControllers(this IServiceCollection services) {
if (services == null) {
throw new ArgumentNullException(nameof(services));
}
internal static IMvcCoreBuilder AddNewtonsoftJson(this IMvcCoreBuilder mvc, Action<MvcJsonOptions> setupAction) {
if (mvc == null) {
throw new ArgumentNullException(nameof(mvc));
}
return services.AddMvcCore();
}
if (setupAction == null) {
throw new ArgumentNullException(nameof(setupAction));
}
// Add JSON formatters that will be used as default ones if no specific formatters are asked for
mvc.AddJsonFormatters();
mvc.AddJsonOptions(setupAction);
return mvc;
internal static IMvcCoreBuilder AddNewtonsoftJson(this IMvcCoreBuilder mvc, Action<MvcJsonOptions> setupAction) {
if (mvc == null) {
throw new ArgumentNullException(nameof(mvc));
}
internal static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action<RequestLocalizationOptions> action) {
if (services == null) {
throw new ArgumentNullException(nameof(services));
}
return services.Configure(action);
if (setupAction == null) {
throw new ArgumentNullException(nameof(setupAction));
}
// Add JSON formatters that will be used as default ones if no specific formatters are asked for
mvc.AddJsonFormatters();
mvc.AddJsonOptions(setupAction);
return mvc;
}
internal static IServiceCollection AddRequestLocalization(this IServiceCollection services, Action<RequestLocalizationOptions> action) {
if (services == null) {
throw new ArgumentNullException(nameof(services));
}
if (action == null) {
throw new ArgumentNullException(nameof(action));
}
return services.Configure(action);
}
#endif
internal static string? GetUnifiedName(this Type type) {