优化扩展

This commit is contained in:
橙子
2021-10-13 15:40:56 +08:00
parent 16eb1fb1e2
commit e9bc71393c
28 changed files with 687 additions and 326 deletions

View File

@@ -9,7 +9,7 @@ namespace Yi.Framework.WebCore
/// <summary>
/// appsettings.json操作类
/// </summary>
public class Appsettings
public class Appsettings
{
static IConfiguration Configuration { get; set; }
static string contentPath { get; set; }
@@ -26,7 +26,7 @@ namespace Yi.Framework.WebCore
.Add(new JsonConfigurationSource { Path = Path, Optional = false, ReloadOnChange = true })//这样的话可以直接读目录里的json文件而不是 bin 文件夹下的,所以不用修改复制属性
.Build();
}
public Appsettings(IConfiguration configuration)
{
Configuration = configuration;
@@ -60,10 +60,16 @@ namespace Yi.Framework.WebCore
/// <returns></returns>
public static T app<T>(params string[] sections)
{
List<T> list = new List<T>();
T app = Activator.CreateInstance<T>();
// 引用 Microsoft.Extensions.Configuration.Binder 包
Configuration.Bind(string.Join(":", sections), list);
return list[0];
Configuration.Bind(string.Join(":", sections), app);
return app;
}
public static IConfiguration appConfiguration(params string[] sections)
{
return Configuration.GetSection(string.Join(":", sections));
}
}
}

View File

@@ -18,7 +18,6 @@ namespace Yi.Framework.WebCore.FilterExtend
{
#region Identity
private readonly ILogger<CustomActionCheckFilterAttribute> _logger;
private readonly IModelMetadataProvider _modelMetadataProvider;
public CustomActionCheckFilterAttribute(ILogger<CustomActionCheckFilterAttribute> logger)
{
this._logger = logger;

View File

@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System;
using System.IO;

View File

@@ -1,27 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System;
using System.IO;
using Yi.Framework.Common.IOCOptions;
namespace Yi.Framework.WebCore.MiddlewareExtend
{
/// <summary>
/// 数据库扩展
/// </summary>
public static class DataBaseExtension
{
public static IServiceCollection AddDataBaseService<IocOptios>(this IServiceCollection services , string appsettings)
{
Appsettings.app<IocOptios>(appsettings);
return services;
}
public static void UseDataBaseService(this IApplicationBuilder app)
{
}
}
}

View File

@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using Yi.Framework.Model;
namespace Yi.Framework.WebCore.MiddlewareExtend
{
/// <summary>
/// 通用跨域扩展
/// </summary>
public static class IocExtension
{
public static IServiceCollection AddIocService(this IServiceCollection services, IConfiguration configuration)
{
#region
//配置文件使用配置
#endregion
services.AddSingleton(new Appsettings(configuration));
#region
//数据库配置
#endregion
services.AddScoped<DbContext, DataContext>();
return services;
}
}
}

View File

@@ -14,7 +14,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static IServiceCollection AddRabbitMQService(this IServiceCollection services)
{
Appsettings.app<RabbitMQOptions>("RabbitConn");
services.Configure<RabbitMQOptions>(Appsettings.appConfiguration("RabbitConn"));
return services;
}
}

View File

@@ -14,7 +14,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static IServiceCollection AddRedisService(this IServiceCollection services)
{
Appsettings.app<RedisConnOptions>("RedisConn");
services.Configure<RedisConnOptions>(Appsettings.appConfiguration("RedisConn"));
return services;
}
}

View File

@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using Yi.Framework.Common.IOCOptions;
namespace Yi.Framework.WebCore.MiddlewareExtend
{
/// <summary>
/// 数据库扩展
/// </summary>
public static class SqliteExtension
{
public static IServiceCollection AddSqliteService(this IServiceCollection services)
{
services.Configure<SqliteOptions>(Appsettings.appConfiguration("SqliteConn"));
return services;
}
}
}

View File

@@ -28,10 +28,10 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
//为 Swagger JSON and UI设置xml文档注释路径
//获取应用程序所在目录(绝对路径不受工作目录影响建议采用此方法获取路径使用windwos&Linux
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
var apiXmlPath = Path.Combine(basePath, @"ApiDoc.xml");//控制器层注释
var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释
var apiXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//控制器层注释
//var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释
//c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释
c.IncludeXmlComments(entityXmlPath);
c.IncludeXmlComments(apiXmlPath);
//添加控制器注释
//c.DocumentFilter<SwaggerDocTag>();

View File

@@ -9,10 +9,12 @@
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
</ItemGroup>
</Project>