mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
@ -34,12 +34,12 @@ namespace aspnetcore_transaction.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("2")]
|
||||
//[Transactional]
|
||||
[Transactional]
|
||||
public async Task<object> GetAsync([FromServices] BaseRepository<Song> repoSong, [FromServices] BaseRepository<Detail> repoDetail, [FromServices] SongRepository repoSong2,
|
||||
[FromServices] SongService serviceSong)
|
||||
{
|
||||
await serviceSong.Test2();
|
||||
await serviceSong.Test3();
|
||||
await repoSong.InsertAsync(new Song());
|
||||
await repoDetail.InsertAsync(new Detail());
|
||||
return "111";
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace aspnetcore_transaction
|
||||
{
|
||||
@ -12,6 +13,11 @@ namespace aspnetcore_transaction
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureLogging(loggerBuilder =>
|
||||
{
|
||||
loggerBuilder.SetMinimumLevel(LogLevel.Critical);
|
||||
//loggerBuilder.ClearProviders();
|
||||
})
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using aspnetcore_transaction.Controllers;
|
||||
using FreeSql;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@ -17,14 +18,18 @@ namespace aspnetcore_transaction
|
||||
{
|
||||
Configuration = configuration;
|
||||
Fsql = new FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\test_trans.db")
|
||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=50;TrustServerCertificate=true")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(cmd => Trace.WriteLine(cmd.CommandText))
|
||||
//.UseMonitorCommand(cmd => Trace.WriteLine(cmd.CommandText))
|
||||
.UseNoneCommandParameter(true)
|
||||
.Build();
|
||||
|
||||
Fsql.Aop.TraceBefore += (_, e) => Trace.WriteLine($"----TraceBefore---{e.Identifier} {e.Operation}");
|
||||
Fsql.Aop.TraceAfter += (_, e) => Trace.WriteLine($"----TraceAfter---{e.Identifier} {e.Operation} {e.Remark} {e.Exception?.Message} {e.ElapsedMilliseconds}ms\r\n");
|
||||
//Fsql.Aop.TraceBefore += (_, e) => Trace.WriteLine($"----TraceBefore---{e.Identifier} {e.Operation}");
|
||||
Fsql.Aop.TraceAfter += (_, e) =>
|
||||
{
|
||||
//Trace.WriteLine($"----TraceAfter---{e.Identifier} {e.Operation} {e.Remark} {e.Exception?.Message} {e.ElapsedMilliseconds}ms\r\n");
|
||||
if (e.Exception != null && e.Exception.Message.StartsWith("【主库】状态不可用,等待后台检查程序恢复方可使用。") == false) Console.WriteLine(e.Exception.Message + " === " + Fsql.Ado.MasterPool.Statistics);
|
||||
};
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
@ -32,6 +37,8 @@ namespace aspnetcore_transaction
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
ThreadPool.SetMinThreads(1000, 1000);
|
||||
|
||||
services.AddControllersWithViews();
|
||||
|
||||
services.AddSingleton<IFreeSql>(Fsql);
|
||||
|
@ -38,6 +38,7 @@ namespace FreeSql
|
||||
if (context.Exception == null) _uow.Commit();
|
||||
else _uow.Rollback();
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
_uow.Dispose();
|
||||
|
Reference in New Issue
Block a user