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.
<PackageVersion Include="DuMes.Expansion.WebApi" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="DuMes.Expansion.WebApi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version 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.
#:package DuMes.Expansion.WebApi@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DuMes.Expansion.WebApi&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=DuMes.Expansion.WebApi&version=1.1.0
                    
Install as a Cake Tool

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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 123 12/14/2024
1.1.6 98 12/14/2024
1.1.5 110 12/14/2024
1.1.4 113 12/12/2024
1.1.3 96 12/10/2024
1.1.2 112 11/28/2024
1.1.1 112 11/27/2024
1.1.0 102 11/27/2024
1.0.9 125 11/25/2024
1.0.8 125 11/25/2024
1.0.7 114 11/25/2024
1.0.6 117 11/25/2024
1.0.5 119 11/25/2024
1.0.4 122 11/25/2024
1.0.3 125 11/25/2024
1.0.2 120 11/25/2024
1.0.1 122 11/25/2024
1.0.0 149 11/21/2024 1.0.0 is deprecated because it is no longer maintained and has critical bugs.