DuMes.Expansion.WebApi 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DuMes.Expansion.WebApi --version 1.1.0                
NuGet\Install-Package DuMes.Expansion.WebApi -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DuMes.Expansion.WebApi" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DuMes.Expansion.WebApi --version 1.1.0                
#r "nuget: DuMes.Expansion.WebApi, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DuMes.Expansion.WebApi as a Cake Addin
#addin nuget:?package=DuMes.Expansion.WebApi&version=1.1.0

// Install DuMes.Expansion.WebApi as a Cake Tool
#tool nuget:?package=DuMes.Expansion.WebApi&version=1.1.0                

DuMes.Expansion.WebApi

介绍

此组件是一个用于扩展WebApi的组件。

包含语言、跨域、Swagger、WebApi以简化WebApi搭建时间

使用说明
  1. 注册语言
//注册语言扩展
builder.Services.AddLanguageExtension();
//使用国际化扩展
app.UseI18NExtension(["zh-CN", "en"]);
  1. 注册跨域
//注册跨域
const string policyName = "DefaultPolicy";
var crossOriginUrls = builder.Configuration.GetSection("CrossOriginUrls").Get<string[]>();
builder.Services.AddCrossOriginExtension(policyName, crossOriginUrls);

//使用跨域
app.UseCors(policyName);
  1. 注册Swagger
//注册Swagger扩展
var swaggerDocument = typeof(SwaggerDocument).GetConstantInClass();
builder.Services.AddSwaggerExtension(swaggerDocument);

//使用Swagger扩展
app.UseSwaggerExtension(swaggerDocument);
  1. 注册WebApi
//注册WebApi扩展
builder.Services.AddWebApiExtension([], jsonOptions =>
{
    //指定格式化方式 
    jsonOptions.SerializerSettings.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
    //返回的日期格式化
    jsonOptions.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
    //返回的结果设置默认序列化
    jsonOptions.SerializerSettings.ContractResolver = new DefaultContractResolver();
}, exceptionHandler => { exceptionHandler.AddExceptionHandler<GlobalExceptionHandler>(); });

//使用WebAPI错误处理程序
app.UseExceptionHandler();

整体Program.cs代码如下

using DuMes.Application.SystemAPI.Contracts;
using DuMes.Expansion.WebApi.Handlers;
using DuMes.Expansion.WebApi.Registers;
using DuMes.Expansion.WebApi.Tools;
using DuMes.Infrastructure.DataStorage.RelationalDatabase;
using DuMes.Infrastructure.DataStorage.RelationalDatabase.SqlSugarExpansion;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

#region 系统基础服务注册
using DuMes.Expansion.WebApi.CrossOrigin;
using DuMes.Expansion.WebApi.Exceptions;
using DuMes.Expansion.WebApi.Expansions;
using DuMes.Expansion.WebApi.Language;
using DuMes.Expansion.WebApi.SwaggerExtension;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using TestWeb.Contracts;

var builder = WebApplication.CreateBuilder(args);

//注册语言扩展
builder.Services.AddLanguageExtension();

//注册跨域
const string policyName = "DefaultPolicy";
var crossOriginUrls = builder.Configuration.GetSection("CrossOriginUrls").Get<string[]>();
builder.Services.AddCrossOriginExtension(policyName, crossOriginUrls);

//注册WebApi扩展
builder.Services.AddWebApiExtension([], jsonOptions =>
{
    //指定格式化方式 
    jsonOptions.SerializerSettings.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
    //返回的日期格式化
    jsonOptions.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
    //返回的结果设置默认序列化
    jsonOptions.SerializerSettings.ContractResolver = new DefaultContractResolver();
}, exceptionHandler => { exceptionHandler.AddExceptionHandler<GlobalExceptionHandler>(); });

//注册Swagger扩展
var swaggerDocument = typeof(SwaggerDocument).GetConstantInClass();
builder.Services.AddSwaggerExtension(swaggerDocument);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
var app = builder.Build();

//使用跨域
app.UseCors(policyName);
//使用语言扩展
app.UseLanguageExtension(["zh-cn", "en"]);
//使用WebAPI错误处理程序
app.UseExceptionHandler();
//使用Swagger扩展
app.UseSwaggerExtension(swaggerDocument);

app.MapControllers();
app.Run();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.7 94 12/14/2024
1.1.6 72 12/14/2024
1.1.5 82 12/14/2024
1.1.4 90 12/12/2024
1.1.3 74 12/10/2024
1.1.2 93 11/28/2024
1.1.1 89 11/27/2024
1.1.0 83 11/27/2024
1.0.9 107 11/25/2024
1.0.8 100 11/25/2024
1.0.7 93 11/25/2024
1.0.6 98 11/25/2024
1.0.5 99 11/25/2024
1.0.4 99 11/25/2024
1.0.3 107 11/25/2024
1.0.2 100 11/25/2024
1.0.1 101 11/25/2024
1.0.0 125 11/21/2024 1.0.0 is deprecated because it is no longer maintained and has critical bugs.