92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Hncore.Pass.Manage.Repository;
|
|
using Hncore.Pass.Manage.Service;
|
|
using Hncore.Pass.Manage.Filters;
|
|
using AutoMapper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
using Hncore.Pass.Manage.Util;
|
|
|
|
|
|
namespace Hncore.Pass.Manage.Util
|
|
{
|
|
/// <summary>
|
|
/// 应用工具类
|
|
/// </summary>
|
|
///
|
|
public static class AppUtil
|
|
{
|
|
/// <summary>
|
|
/// 当前应用的服务专用扩展配置
|
|
/// </summary>
|
|
/// <param name="services">服务集合(容器对象)</param>
|
|
/// <returns>服务集合(容器对象)</returns>
|
|
///
|
|
public static IServiceCollection MyServicesSpecialUseConfigure(this IServiceCollection services)
|
|
{
|
|
LoadServicesToContainer(services);//配置服务依赖注入
|
|
RegisterGlobalFilters(services);//注册全局过滤器
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前应用的专用扩展配置
|
|
/// </summary>
|
|
/// <param name="app">用于构建应用程序的请求管道</param>
|
|
/// <param name="env">提供了当前应用程序的运行的宿主环境配置信息</param>
|
|
/// <param name="loggerFactory">日志工厂</param>
|
|
///
|
|
public static void MySpecialUseConfigure(this IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
{
|
|
AutoMapperConfig();//AutoMapper映射配置
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将当前项目常用的服务加载到容器中管理起来(该函数会在Startup中的ConfigureServices)
|
|
/// </summary>
|
|
/// <param name="services">服务集合(容器对象)</param>
|
|
private static void LoadServicesToContainer(IServiceCollection services)
|
|
{
|
|
/**********添加服务相关类**********/
|
|
services.AddScoped<ManagerTagService>();//管理员标签服务
|
|
services.AddScoped<ManagerService>();//管理员服务
|
|
|
|
services.AddScoped<ManagerPermissionService>();//管理员权限菜单
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// AutoMapper配置
|
|
/// </summary>
|
|
///
|
|
private static void AutoMapperConfig()
|
|
{
|
|
Mapper.Initialize(c => {
|
|
c.AddProfile<AutoMapperProfile>();//指定映射关系处理类
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 注册全局过滤器
|
|
/// </summary>
|
|
/// <param name="services">服务集合(容器对象)</param>
|
|
private static void RegisterGlobalFilters(IServiceCollection services)
|
|
{
|
|
//services.AddMvc(c => {
|
|
// c.Filters.Add<HttpGlobalExceptionFilter>();//全局异常过滤器
|
|
//});
|
|
}
|
|
}
|
|
}
|