Пример #1
0
 /// <summary>
 ///
 /// </summary>
 public TestController(//IJwtService jwtService,
     IConfiguration configuration,
     AllConfigModel allConfigModel
     )
 {
     _config         = configuration;
     _allConfigModel = allConfigModel;
     //_jwtService = jwtService;
 }
Пример #2
0
 public TestController(IConfiguration configuration,
                       AllConfigModel allConfigModel,
                       IHostingEnvironment env,
                       IJwtService jwtService)
 {
     _config         = configuration;
     _allConfigModel = allConfigModel;
     _env            = env;
     _jwtService     = jwtService;
 }
Пример #3
0
        /// <summary>
        /// 注册服务到[依赖注入容器]
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            //注册控制器
            services.AddControllers(options =>
            {
                options.Filters.Add(typeof(WebApiResultFilterAttribute));
                options.RespectBrowserAcceptHeader = true;
            }).AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";//设置时间格式
            });

            //注册配置管理服务
            services.AddSingleton <IConfiguration>(_configuration);
            services.AddMyOptions();
            services.AddConfigService(_env.ContentRootPath);
            AllConfigModel allConfig = services.GetImplementationInstanceOrNull <AllConfigModel>();

            //注册Swagger
            services.AddSwaggerService();

            //注册授权认证

            JwtAuthConfigModel jwtConfig = allConfig.JwtAuthConfigModel;
            var jwtOption = new JwtOption//todo:使用AutoMapper替换
            {
                Issuer         = jwtConfig.Issuer,
                Audience       = jwtConfig.Audience,
                WebExp         = jwtConfig.WebExp,
                AppExp         = jwtConfig.AppExp,
                MiniProgramExp = jwtConfig.MiniProgramExp,
                OtherExp       = jwtConfig.OtherExp,
                SecurityKey    = jwtConfig.SecurityKey
            };

            services.AddSingleton(jwtOption);
            services.AddRayAuthService(jwtOption);

            //services.AddSecurityService();

            //注册Cors跨域
            services.AddCorsService();

            //注册http上下文访问器
            services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();

            //注册仓储
            //string connStr = allConfig.ConnectionStringsModel.SqlServerDatabase;
            services.AddMyRepository();

            //注册业务逻辑
            services.AddMyAppServices();

            LogServices(services);
        }
Пример #4
0
        public static IServiceCollection AddConfigService(this IServiceCollection services, string basePath)
        {
            IConfigurationBuilder builder = new ConfigurationBuilder()
                                            .SetBasePath(basePath)
                                            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                                            .AddJsonFile("appsettings.Development.json", true, true);
            var config = builder.Build();

            services.AddSingleton(config);

            var allConfigModel = new AllConfigModel(config);

            services.AddSingleton(allConfigModel);

            return(services);
        }
Пример #5
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            //注册MVC
            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";    //设置时间格式
            });

            //注册配置管理服务
            services.AddConfigService(_env.ContentRootPath);
            AllConfigModel allConfig = services.GetSingletonInstanceOrNull <AllConfigModel>();

            //注册Swagger
            services.AddSwaggerService();

            //注册授权认证
            JwtAuthConfigModel jwtConfig = allConfig.JwtAuthConfigModel;
            var jwtOption = new JwtOption//todo:使用AutoMapper替换
            {
                WebExp         = jwtConfig.WebExp,
                AppExp         = jwtConfig.AppExp,
                MiniProgramExp = jwtConfig.MiniProgramExp,
                OtherExp       = jwtConfig.OtherExp,
                SecurityKey    = jwtConfig.SecurityKey
            };

            services.AddAuthService(jwtOption);

            //注册Cors跨域
            services.AddCorsService();

            //注册http上下文访问器
            services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();

            //注册仓储
            string connStr = allConfig.ConnectionStringsModel.SqlServerDatabase;

            services.AddRepository(connStr);

            //注册业务逻辑
            services.AddBusiness();
        }
Пример #6
0
        /// <summary>
        /// 注册服务到[依赖注入容器]
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            //注册控制器
            services.AddControllers(options =>
            {
                //options.Filters.Add(typeof(WebApiResultFilterAttribute));
                options.RespectBrowserAcceptHeader = true;
            })
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";    //设置时间格式
            });

            //注册配置管理服务
            services.AddConfigService(_env.ContentRootPath);
            AllConfigModel allConfig = services.GetImplementationInstanceOrNull <AllConfigModel>();

            //注册Swagger
            services.AddSwaggerService();

            //注册授权认证
            JwtAuthConfigModel jwtConfig = allConfig.JwtAuthConfigModel;
            var jwtOption = AutoMapperHelper.Map <JwtAuthConfigModel, JwtOption>(jwtConfig);

            services.AddSingleton(jwtOption);
            services.AddRayAuthService(jwtOption);

            //services.AddSecurityService();

            //注册Cors跨域
            services.AddCorsService();

            //注册http上下文访问器
            services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();

            //注册业务逻辑
            services.AddMyAppServices(_configuration);
            services.AddMyRepository(_configuration);
        }
Пример #7
0
 public AccountController(IAuthService authService, IJwtService jwtService, AllConfigModel allConfigModel)
 {
     _authService    = authService;
     _jwtService     = jwtService;
     _allConfigModel = allConfigModel;
 }