mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 调整 Ado.AopCommandExecuting/AopCommandExecuted 到 Aop.CommandBefore/After; - 增加 Aop.TraceBefore/After 事件;
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using Microsoft.AspNetCore.Builder;
 | 
						|
using Microsoft.Extensions.Configuration;
 | 
						|
using Microsoft.Extensions.DependencyInjection;
 | 
						|
using Microsoft.Extensions.Logging;
 | 
						|
using System;
 | 
						|
using System.Text;
 | 
						|
 | 
						|
namespace restful
 | 
						|
{
 | 
						|
    public class Startup
 | 
						|
    {
 | 
						|
        public Startup(IConfiguration configuration, ILoggerFactory loggerFactory)
 | 
						|
        {
 | 
						|
            Configuration = configuration;
 | 
						|
 | 
						|
            Fsql = new FreeSql.FreeSqlBuilder()
 | 
						|
                .UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
 | 
						|
                .UseAutoSyncStructure(true)
 | 
						|
                .Build();
 | 
						|
 | 
						|
            Fsql.Aop.CurdAfter += (s, e) =>
 | 
						|
            {
 | 
						|
                if (e.ElapsedMilliseconds > 200)
 | 
						|
                {
 | 
						|
                    //记录日志
 | 
						|
                    //发送短信给负责人
 | 
						|
                }
 | 
						|
            };
 | 
						|
 | 
						|
            //Fsql.Aop.Where = (s, e) => {
 | 
						|
            //	if (e.Parameters[0]?.ToString() == "1")
 | 
						|
            //		e.IsCancel = true;
 | 
						|
            //};
 | 
						|
        }
 | 
						|
 | 
						|
        public IConfiguration Configuration { get; }
 | 
						|
        public IFreeSql Fsql { get; }
 | 
						|
 | 
						|
        public void ConfigureServices(IServiceCollection services)
 | 
						|
        {
 | 
						|
            services.AddSingleton<IFreeSql>(Fsql);
 | 
						|
            services.AddControllersWithViews();
 | 
						|
        }
 | 
						|
 | 
						|
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
 | 
						|
        {
 | 
						|
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
 | 
						|
            Console.OutputEncoding = Encoding.GetEncoding("GB2312");
 | 
						|
            Console.InputEncoding = Encoding.GetEncoding("GB2312");
 | 
						|
 | 
						|
            app.UseHttpMethodOverride(new HttpMethodOverrideOptions { FormFieldName = "X-Http-Method-Override" });
 | 
						|
            app.UseDeveloperExceptionPage();
 | 
						|
            app.UseRouting();
 | 
						|
            app.UseEndpoints(a => a.MapControllers());
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |