// 这里可以注入 public Job1TimedService(IBlogArticleServices blogArticleServices) { _blogArticleServices = blogArticleServices; }
/// <summary> /// 构造函数 /// </summary> /// <param name="advertisementServices"></param> /// <param name="blogArticleServices"></param> /// <param name="redisCacheManager"></param> public BlogController(IAdvertisementServices advertisementServices, IBlogArticleServices blogArticleServices, IRedisCacheManager redisCacheManager) { this.advertisementServices = advertisementServices; this.blogArticleServices = blogArticleServices; this.redisCacheManager = redisCacheManager; }
/// <summary> /// 构造函数 /// </summary> /// <param name="blogArticleServices"></param> /// <param name="logger"></param> public BlogController(IBlogArticleServices blogArticleServices, ILogger <BlogController> logger) { _logger = logger; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IBlogArticleServices _blogArticleServices, ILoggerFactory loggerFactory) { // Ip限流,尽量放管道外层 app.UseIpRateLimiting(); // 记录所有的访问记录 loggerFactory.AddLog4Net(); // 记录请求与返回数据 app.UseReuestResponseLog(); // signalr app.UseSignalRSendMildd(); // 记录ip请求 app.UseIPLogMildd(); // 查看注入的所有服务 app.UseAllServicesMildd(_services, tsDIAutofac); #region Environment if (env.IsDevelopment()) { // 在开发环境中,使用异常页面,这样可以暴露错误堆栈信息,所以不要放在生产环境。 app.UseDeveloperExceptionPage(); //app.Use(async (context, next) => //{ // //这里会多次调用,这里测试一下就行,不要打开注释 // //var blogs =await _blogArticleServices.GetBlogs(); // var processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; // Console.WriteLine(processName); // await next(); //}); } else { app.UseExceptionHandler("/Error"); // 在非开发环境中,使用HTTP严格安全传输(or HSTS) 对于保护web安全是非常重要的。 // 强制实施 HTTPS 在 ASP.NET Core,配合 app.UseHttpsRedirection //app.UseHsts(); } #endregion #region Swagger app.UseSwagger(); app.UseSwaggerUI(c => { //根据版本名称倒序 遍历展示 var ApiName = Appsettings.app(new string[] { "Startup", "ApiName" }); typeof(ApiVersions).GetEnumNames().OrderByDescending(e => e).ToList().ForEach(version => { c.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"{ApiName} {version}"); }); // 将swagger首页,设置成我们自定义的页面,记得这个字符串的写法:解决方案名.index.html // index.html的属性,必须是设置为嵌入的资源 c.IndexStream = () => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("Blog.Core.index.html"); // 路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件,注意localhost:8001/swagger是访问不到的,去launchSettings.json把launchUrl去掉,如果你想换一个路径,直接写名字即可,比如直接写c.RoutePrefix = "doc"; c.RoutePrefix = ""; }); #endregion // ↓↓↓↓↓↓ 注意下边这些中间件的顺序,很重要 ↓↓↓↓↓↓ app.UseCors("LimitRequests"); // 跳转https //app.UseHttpsRedirection(); // 使用静态文件 app.UseStaticFiles(); // 使用cookie app.UseCookiePolicy(); // 返回错误码 app.UseStatusCodePages();//把错误码返回前台,比如是404 // Routing app.UseRouting(); // 这种自定义授权中间件,可以尝试,但不推荐 // app.UseJwtTokenAuth(); // 先开启认证 app.UseAuthentication(); // 然后是授权中间件 app.UseAuthorization(); // 开启异常中间件,要放到最后 //app.UseExceptionHandlerMidd(); app.UseMiniProfiler(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapHub <ChatHub>("/api2/chatHub"); }); }
public BlogArticleController(IBlogArticleServices _BlogArticleServices) { this._BlogArticleServices = _BlogArticleServices; }
public UseServiceDIAttribute(ILogger <UseServiceDIAttribute> logger, IBlogArticleServices blogArticleServices, string Name = "") { _logger = logger; _blogArticleServices = blogArticleServices; _name = Name; }
public BlogArticleController(IBlogArticleServices BlogArticleServices) { _blogArticleServices = BlogArticleServices; }
public BlogController(IBlogArticleServices blogArticleServices) { _blogArticleServices = blogArticleServices; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IBlogArticleServices _blogArticleServices) { #region ReuestResponseLog if (Appsettings.app("AppSettings", "Middleware_RequestResponse", "Enabled").ObjToBool()) { app.UseReuestResponseLog();//记录请求与返回数据 } #endregion #region Environment if (env.IsDevelopment()) { // 在开发环境中,使用异常页面,这样可以暴露错误堆栈信息,所以不要放在生产环境。 app.UseDeveloperExceptionPage(); //app.Use(async (context, next) => //{ // //这里会多次调用,这里测试一下就行,不要打开注释 // //var blogs =await _blogArticleServices.GetBlogs(); // var processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; // Console.WriteLine(processName); // await next(); //}); } else { app.UseExceptionHandler("/Error"); // 在非开发环境中,使用HTTP严格安全传输(or HSTS) 对于保护web安全是非常重要的。 // 强制实施 HTTPS 在 ASP.NET Core,配合 app.UseHttpsRedirection //app.UseHsts(); } #endregion #region Swagger app.UseSwagger(); app.UseSwaggerUI(c => { //根据版本名称倒序 遍历展示 typeof(ApiVersions).GetEnumNames().OrderByDescending(e => e).ToList().ForEach(version => { c.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"{ApiName} {version}"); }); // 将swagger首页,设置成我们自定义的页面,记得这个字符串的写法:解决方案名.index.html /* c.IndexStream = () => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("AnkouBlog.index.html");/*/ //这里是配合MiniProfiler进行性能监控的,《文章:完美基于AOP的接口性能分析》,如果你不需要,可以暂时先注释掉,不影响大局。 c.RoutePrefix = ""; //路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件,注意localhost:8001/swagger是访问不到的,去launchSettings.json把launchUrl去掉 }); #endregion #region MiniProfiler app.UseMiniProfiler(); #endregion #region 第三步:开启认证中间件 //如果你想使用官方认证,必须在上边ConfigureService 中,配置JWT的认证服务 (.AddAuthentication 和 .AddJwtBearer 二者缺一不可) app.UseAuthentication(); #endregion #region CORS //跨域第二种方法,使用策略,详细策略信息在ConfigureService中 app.UseCors("LimitRequests");//将 CORS 中间件添加到 web 应用程序管线中, 以允许跨域请求。 #endregion // 跳转https //app.UseHttpsRedirection(); // 使用静态文件 app.UseStaticFiles(); // 使用cookie app.UseCookiePolicy(); // 返回错误码 app.UseStatusCodePages();//把错误码返回前台,比如是404 app.UseMvc(); app.UseSignalR(routes => { //这里要说下,为啥地址要写 /api/xxx //因为我前后端分离了,而且使用的是代理模式,所以如果你不用/api/xxx的这个规则的话,会出现跨域问题,毕竟这个不是我的controller的路由,而且自己定义的路由 routes.MapHub <ChatHub>("/api2/chatHub"); }); }
public LSBlogController(IAdvertisementServices services, IBlogArticleServices dal, IRedisCacheManager redisCache) { _services = services; _dal = dal; _redisCache = redisCache; }
/// <summary> /// 构造函数 /// </summary> /// <param name="advertisementServices"></param> public BlogController(IAdvertisementServices advertisementServices, IBlogArticleServices blogArticleServices) { this.advertisementServices = advertisementServices; this.blogArticleServices = blogArticleServices; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IBlogArticleServices _blogArticleServices, ILoggerFactory loggerFactory) { #region RecordAllLogs if (Appsettings.app("AppSettings", "Middleware_RecordAllLogs", "Enabled").ObjToBool()) { loggerFactory.AddLog4Net();//记录所有的访问记录 } #endregion #region ReuestResponseLog if (Appsettings.app("AppSettings", "Middleware_RequestResponse", "Enabled").ObjToBool()) { app.UseReuestResponseLog();//记录请求与返回数据 } #endregion #region Environment if (env.IsDevelopment()) { // 在开发环境中,使用异常页面,这样可以暴露错误堆栈信息,所以不要放在生产环境。 app.UseDeveloperExceptionPage(); //app.Use(async (context, next) => //{ // //这里会多次调用,这里测试一下就行,不要打开注释 // //var blogs =await _blogArticleServices.GetBlogs(); // var processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; // Console.WriteLine(processName); // await next(); //}); } else { app.UseExceptionHandler("/Error"); // 在非开发环境中,使用HTTP严格安全传输(or HSTS) 对于保护web安全是非常重要的。 // 强制实施 HTTPS 在 ASP.NET Core,配合 app.UseHttpsRedirection //app.UseHsts(); } #endregion #region Swagger app.UseSwagger(); app.UseSwaggerUI(c => { //根据版本名称倒序 遍历展示 typeof(ApiVersions).GetEnumNames().OrderByDescending(e => e).ToList().ForEach(version => { c.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"{ApiName} {version}"); }); // 将swagger首页,设置成我们自定义的页面,记得这个字符串的写法:解决方案名.index.html c.IndexStream = () => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("Blog.Core.index.html"); //这里是配合MiniProfiler进行性能监控的,《文章:完美基于AOP的接口性能分析》,如果你不需要,可以暂时先注释掉,不影响大局。 c.RoutePrefix = ""; //路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件,注意localhost:8001/swagger是访问不到的,去launchSettings.json把launchUrl去掉,如果你想换一个路径,直接写名字即可,比如直接写c.RoutePrefix = "doc"; }); #endregion #region MiniProfiler app.UseMiniProfiler(); #endregion #region CORS //跨域第二种方法,使用策略,详细策略信息在ConfigureService中 app.UseCors("LimitRequests");//将 CORS 中间件添加到 web 应用程序管线中, 以允许跨域请求。 #region 跨域第一种版本 //跨域第一种版本,请要ConfigureService中配置服务 services.AddCors(); // app.UseCors(options => options.WithOrigins("http://localhost:8021").AllowAnyHeader() //.AllowAnyMethod()); #endregion #endregion // 跳转https //app.UseHttpsRedirection(); // 使用静态文件 app.UseStaticFiles(); // 使用cookie app.UseCookiePolicy(); // 返回错误码 app.UseStatusCodePages();//把错误码返回前台,比如是404 app.UseRouting(); #region 第三步:开启认证中间件 //此授权认证方法已经放弃,请使用下边的官方验证方法。但是如果你还想传User的全局变量,还是可以继续使用中间件,第二种写法//app.UseMiddleware<JwtTokenAuth>(); //app.UseJwtTokenAuth(); //如果你想使用官方认证,必须在上边ConfigureService 中,配置JWT的认证服务 (.AddAuthentication 和 .AddJwtBearer 二者缺一不可) app.UseAuthentication(); #endregion app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapHub <ChatHub>("/api2/chatHub"); }); }
/// <summary> /// /// </summary> /// <param name="next"></param> /// <param name="blogArticleServices"></param> public RequRespLogMildd(RequestDelegate next, IBlogArticleServices blogArticleServices) { _next = next; _blogArticleServices = blogArticleServices; }
public Job_Blogs_Quartz(IBlogArticleServices blogArticleServices, ITasksQzServices tasksQzServices) { _blogArticleServices = blogArticleServices; _tasksQzServices = tasksQzServices; }
/// <summary> /// 构造函数 /// </summary> /// <param name="blogArticleServices"></param> /// <param name="redisCacheManager"></param> /// <param name="logger"></param> public BlogController(IBlogArticleServices blogArticleServices, IRedisCacheManager redisCacheManager, ILogger <BlogController> logger) { _blogArticleServices = blogArticleServices; _redisCacheManager = redisCacheManager; _logger = logger; }