練習資料庫紀錄完成
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coreprofiler" Version="1.1.4" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
14
CoreProfilerExample.Common/IDatabaseOption.cs
Normal file
14
CoreProfilerExample.Common/IDatabaseOption.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CoreProfilerExample.Common
|
||||
{
|
||||
public interface IDatabaseOption
|
||||
{
|
||||
public IDbConnection SqliteConnection { get; }
|
||||
}
|
||||
}
|
||||
30
CoreProfilerExample.Common/Options/DatabaseOption.cs
Normal file
30
CoreProfilerExample.Common/Options/DatabaseOption.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using CoreProfiler;
|
||||
using CoreProfiler.Data;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CoreProfilerExample.Common.Options
|
||||
{
|
||||
public class DatabaseOption(IConfiguration configuration) : IDatabaseOption
|
||||
{
|
||||
public IDbConnection SqliteConnection
|
||||
{
|
||||
get
|
||||
{
|
||||
var connectionString = configuration.GetConnectionString("SQLITE");
|
||||
|
||||
var dbProfiler = ProfilingSession.Current != null
|
||||
? new DbProfiler(ProfilingSession.Current.Profiler)
|
||||
: null;
|
||||
|
||||
return new ProfiledDbConnection(new SqliteConnection(connectionString), dbProfiler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user