From 29b04fd16983a198c7fb0d24059b8b16b4a651db Mon Sep 17 00:00:00 2001
From: Nice <2017875139@qq.com>
Date: Tue, 22 Feb 2022 15:26:28 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Easy.sln | 37 +++++
src/Easy.Api/ApiService.cs | 7 +
src/Easy.Api/Easy.Api.csproj | 17 ++
.../RouteHandlerBuilderExtensions.cs | 43 +++++
.../ServiceCollectionServiceExtensions.cs | 42 +++++
src/Easy.Api/FirstTemplateAttribute.cs | 24 +++
src/Easy.Api/IgnoreAttribute.cs | 16 ++
.../Middlewares/AnnotationsOperationFilter.cs | 140 ++++++++++++++++
src/Easy.Api/Realization/ApiMapAuto.cs | 55 +++++++
.../Realization/AppServiceActivator.cs | 25 +++
.../AppServiceControllerFeatureProvider.cs | 16 ++
.../Realization/ApplicationConvention.cs | 149 ++++++++++++++++++
src/Easy.Api/_Imports.cs | 2 +
src/Easy.DI/Easy.DI.csproj | 13 ++
.../ServiceCollectionServiceExtensions.cs | 28 ++++
src/Easy.DI/ILazyServiceProvider.cs | 20 +++
src/Easy.DI/IScopedDependency.cs | 8 +
src/Easy.DI/ISingletonDependency.cs | 8 +
src/Easy.DI/ITransientDependency.cs | 8 +
.../Realization/DependencyInterface.cs | 52 ++++++
.../Realization/LazyServiceProvider.cs | 73 +++++++++
src/Easy.DI/_Imports.cs | 2 +
src/Easy.Result/ApiResult.cs | 27 ++++
src/Easy.Result/ApiResultConsts.cs | 13 ++
src/Easy.Result/ApiResultPaged.cs | 18 +++
src/Easy.Result/ApiResultValue.cs | 11 ++
src/Easy.Result/ApiResultValues.cs | 11 ++
src/Easy.Result/Common/AutoMapReadonly.cs | 24 +++
src/Easy.Result/Easy.Result.csproj | 16 ++
src/Easy.Result/Exceptions/SvcException.cs | 18 +++
.../Extensions/ApiResultExtensions.cs | 77 +++++++++
.../ApplicationBuilderExtensions.cs | 22 +++
.../FluentValidationRegister.cs | 36 +++++
src/Easy.Result/IEntities.cs | 65 ++++++++
src/Easy.Result/IEntity.cs | 10 ++
src/Easy.Result/IModel.cs | 9 ++
.../Middlewares/ErrApiResMiddleware.cs | 51 ++++++
src/Easy.Result/PagingRequest.cs | 38 +++++
src/Easy.Result/When.cs | 20 +++
39 files changed, 1251 insertions(+)
create mode 100644 Easy.sln
create mode 100644 src/Easy.Api/ApiService.cs
create mode 100644 src/Easy.Api/Easy.Api.csproj
create mode 100644 src/Easy.Api/Extensions/RouteHandlerBuilderExtensions.cs
create mode 100644 src/Easy.Api/Extensions/ServiceCollectionServiceExtensions.cs
create mode 100644 src/Easy.Api/FirstTemplateAttribute.cs
create mode 100644 src/Easy.Api/IgnoreAttribute.cs
create mode 100644 src/Easy.Api/Middlewares/AnnotationsOperationFilter.cs
create mode 100644 src/Easy.Api/Realization/ApiMapAuto.cs
create mode 100644 src/Easy.Api/Realization/AppServiceActivator.cs
create mode 100644 src/Easy.Api/Realization/AppServiceControllerFeatureProvider.cs
create mode 100644 src/Easy.Api/Realization/ApplicationConvention.cs
create mode 100644 src/Easy.Api/_Imports.cs
create mode 100644 src/Easy.DI/Easy.DI.csproj
create mode 100644 src/Easy.DI/Extensions/ServiceCollectionServiceExtensions.cs
create mode 100644 src/Easy.DI/ILazyServiceProvider.cs
create mode 100644 src/Easy.DI/IScopedDependency.cs
create mode 100644 src/Easy.DI/ISingletonDependency.cs
create mode 100644 src/Easy.DI/ITransientDependency.cs
create mode 100644 src/Easy.DI/Realization/DependencyInterface.cs
create mode 100644 src/Easy.DI/Realization/LazyServiceProvider.cs
create mode 100644 src/Easy.DI/_Imports.cs
create mode 100644 src/Easy.Result/ApiResult.cs
create mode 100644 src/Easy.Result/ApiResultConsts.cs
create mode 100644 src/Easy.Result/ApiResultPaged.cs
create mode 100644 src/Easy.Result/ApiResultValue.cs
create mode 100644 src/Easy.Result/ApiResultValues.cs
create mode 100644 src/Easy.Result/Common/AutoMapReadonly.cs
create mode 100644 src/Easy.Result/Easy.Result.csproj
create mode 100644 src/Easy.Result/Exceptions/SvcException.cs
create mode 100644 src/Easy.Result/Extensions/ApiResultExtensions.cs
create mode 100644 src/Easy.Result/Extensions/ApplicationBuilderExtensions.cs
create mode 100644 src/Easy.Result/FluentValidation/FluentValidationRegister.cs
create mode 100644 src/Easy.Result/IEntities.cs
create mode 100644 src/Easy.Result/IEntity.cs
create mode 100644 src/Easy.Result/IModel.cs
create mode 100644 src/Easy.Result/Middlewares/ErrApiResMiddleware.cs
create mode 100644 src/Easy.Result/PagingRequest.cs
create mode 100644 src/Easy.Result/When.cs
diff --git a/Easy.sln b/Easy.sln
new file mode 100644
index 0000000..422b084
--- /dev/null
+++ b/Easy.sln
@@ -0,0 +1,37 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.1.32210.238
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Easy.Api", "src\Easy.Api\Easy.Api.csproj", "{689367DF-1216-40A5-91CE-412EE8FE6C8F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Easy.DI", "src\Easy.DI\Easy.DI.csproj", "{A269FF3D-00BC-499D-A496-46D97D51FE92}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Easy.Result", "src\Easy.Result\Easy.Result.csproj", "{82677F0B-E9CF-4491-8B04-9BF9B04B1534}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {689367DF-1216-40A5-91CE-412EE8FE6C8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {689367DF-1216-40A5-91CE-412EE8FE6C8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {689367DF-1216-40A5-91CE-412EE8FE6C8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {689367DF-1216-40A5-91CE-412EE8FE6C8F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A269FF3D-00BC-499D-A496-46D97D51FE92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A269FF3D-00BC-499D-A496-46D97D51FE92}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A269FF3D-00BC-499D-A496-46D97D51FE92}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A269FF3D-00BC-499D-A496-46D97D51FE92}.Release|Any CPU.Build.0 = Release|Any CPU
+ {82677F0B-E9CF-4491-8B04-9BF9B04B1534}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {82677F0B-E9CF-4491-8B04-9BF9B04B1534}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {82677F0B-E9CF-4491-8B04-9BF9B04B1534}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {82677F0B-E9CF-4491-8B04-9BF9B04B1534}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {7260112B-0232-4725-AB84-EF4DCCABFD77}
+ EndGlobalSection
+EndGlobal
diff --git a/src/Easy.Api/ApiService.cs b/src/Easy.Api/ApiService.cs
new file mode 100644
index 0000000..653ac63
--- /dev/null
+++ b/src/Easy.Api/ApiService.cs
@@ -0,0 +1,7 @@
+using Microsoft.AspNetCore.Routing;
+
+namespace Easy.Api;
+public abstract class ApiService
+{
+
+}
\ No newline at end of file
diff --git a/src/Easy.Api/Easy.Api.csproj b/src/Easy.Api/Easy.Api.csproj
new file mode 100644
index 0000000..f30fb54
--- /dev/null
+++ b/src/Easy.Api/Easy.Api.csproj
@@ -0,0 +1,17 @@
+
+
+ net6.0
+ enable
+ True
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Easy.Api/Extensions/RouteHandlerBuilderExtensions.cs b/src/Easy.Api/Extensions/RouteHandlerBuilderExtensions.cs
new file mode 100644
index 0000000..0836fc0
--- /dev/null
+++ b/src/Easy.Api/Extensions/RouteHandlerBuilderExtensions.cs
@@ -0,0 +1,43 @@
+using Easy.Api.Realization;
+using Microsoft.AspNetCore.Routing;
+using Swashbuckle.AspNetCore.Annotations;
+
+namespace Easy.Api.Extensions;
+
+///
+/// A class containing extension methods for the class. This class cannot be inherited.
+///
+public static class RouteHandlerBuilderExtensions
+{
+ ///
+ /// Adds the to the metadata for all builders produced by builder.
+ ///
+ /// The .
+ /// The operation summary.
+ /// The optional operation description.
+ ///
+ /// A that can be used to further customize the endpoint.
+ ///
+ public static RouteHandlerBuilder WithDescription(
+ this RouteHandlerBuilder builder,
+ string summary,
+ string description = null)
+ {
+ return builder.WithMetadata(new SwaggerOperationAttribute(summary, description));
+ }
+ ///
+ /// 路由模板 App名称带头
+ ///
+ //public static ApiMapAuto AutoApi(this IEndpointRouteBuilder endpoint, string template)
+ //{
+ // if (string.IsNullOrEmpty(template))
+ // {
+ // template = "app";
+ // }
+ // if (!template.StartsWith("api"))
+ // {
+ // template = "api/" + template;
+ // }
+ // return new ApiMapAuto(template, endpoint);
+ //}
+}
diff --git a/src/Easy.Api/Extensions/ServiceCollectionServiceExtensions.cs b/src/Easy.Api/Extensions/ServiceCollectionServiceExtensions.cs
new file mode 100644
index 0000000..5ae58db
--- /dev/null
+++ b/src/Easy.Api/Extensions/ServiceCollectionServiceExtensions.cs
@@ -0,0 +1,42 @@
+using Easy.Api;
+using Easy.Api.Realization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Controllers;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+
+namespace Easy.Api.Extensions;
+public static class ServiceCollectionServiceExtensions
+{
+ ///
+ /// 动态代理Api
+ ///
+ public static IMvcBuilder AddDynamicWebApi(this IServiceCollection services)
+ {
+
+ var build = services.AddControllers();
+
+ build.ConfigureApplicationPartManager(applicationPartManager =>
+ {
+ applicationPartManager.FeatureProviders.Add(new AppServiceControllerFeatureProvider());
+ });
+
+ ControllerFeature feature = new();
+
+ build.PartManager.PopulateFeature(feature);
+
+ foreach (var controller in feature.Controllers.Select(c => c.AsType()).Where(o => o != typeof(ApiService)))// 禁用父类
+ {
+ services.TryAddTransient(controller, controller);
+ }
+
+ services.Replace(ServiceDescriptor.Transient());
+
+ services.Configure(options =>
+ {
+ options.Conventions.Add(new ApplicationConvention());
+ });
+
+ return build;
+ }
+
+}
diff --git a/src/Easy.Api/FirstTemplateAttribute.cs b/src/Easy.Api/FirstTemplateAttribute.cs
new file mode 100644
index 0000000..add213c
--- /dev/null
+++ b/src/Easy.Api/FirstTemplateAttribute.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Easy.Api;
+
+///
+/// api定义?
+///
+[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
+public class FirstTemplateAttribute : Attribute
+{
+ public string FirstTemplate { get; }
+ public FirstTemplateAttribute()
+ {
+ FirstTemplate = "";
+ }
+ public FirstTemplateAttribute(string firstTemplate)
+ {
+ FirstTemplate = firstTemplate;
+ }
+}
diff --git a/src/Easy.Api/IgnoreAttribute.cs b/src/Easy.Api/IgnoreAttribute.cs
new file mode 100644
index 0000000..9a0c97f
--- /dev/null
+++ b/src/Easy.Api/IgnoreAttribute.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Easy.Api;
+
+///
+/// 忽略
+///
+[AttributeUsage(AttributeTargets.Parameter)]
+public class ParamIgnoreAttribute : Attribute
+{
+
+}
diff --git a/src/Easy.Api/Middlewares/AnnotationsOperationFilter.cs b/src/Easy.Api/Middlewares/AnnotationsOperationFilter.cs
new file mode 100644
index 0000000..0f86fc1
--- /dev/null
+++ b/src/Easy.Api/Middlewares/AnnotationsOperationFilter.cs
@@ -0,0 +1,140 @@
+using Microsoft.OpenApi.Models;
+using Swashbuckle.AspNetCore.Annotations;
+using Swashbuckle.AspNetCore.SwaggerGen;
+using System.Globalization;
+
+namespace Easy.Api.Middlewares;
+
+public class AnnotationsOperationFilter : IOperationFilter
+{
+ public void Apply(OpenApiOperation operation, OperationFilterContext context)
+ {
+ IEnumerable