refactor: 优化 PetaPoco 数据服务接口
This commit is contained in:
parent
913f4db051
commit
15007cd2fc
|
@ -26,14 +26,14 @@ public static class ServicesExtensions
|
|||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddPetaPocoDataAccessServices(this IServiceCollection services)
|
||||
public static IServiceCollection AddPetaPocoDataAccessServices(this IServiceCollection services, Action<IServiceProvider, IDatabaseBuildConfiguration> builder)
|
||||
{
|
||||
services.TryAddSingleton<IDatabase>(provider =>
|
||||
{
|
||||
//TODO: 后期改造成自定适配
|
||||
var configuration = provider.GetRequiredService<IConfiguration>();
|
||||
var connString = configuration.GetConnectionString("bb");
|
||||
var db = new Database<SQLiteDatabaseProvider>(connString, new BootstrapAdminConventionMapper());
|
||||
var option = DatabaseConfiguration.Build();
|
||||
builder(provider, option);
|
||||
option.UsingDefaultMapper<BootstrapAdminConventionMapper>();
|
||||
var db = new Database(option);
|
||||
|
||||
var logger = provider.GetRequiredService<ILogger<Database>>();
|
||||
db.ExceptionThrown += (sender, e) =>
|
||||
|
|
|
@ -3,10 +3,8 @@ using BootstrapAdmin.Web.Services;
|
|||
using BootstrapAdmin.Web.Services.SMS;
|
||||
using BootstrapAdmin.Web.Services.SMS.Tencent;
|
||||
using BootstrapAdmin.Web.Utils;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
using PetaPoco;
|
||||
using PetaPoco.Providers;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
|
@ -49,7 +47,13 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
//});
|
||||
|
||||
// 增加 PetaPoco 数据服务
|
||||
services.AddPetaPocoDataAccessServices();
|
||||
services.AddPetaPocoDataAccessServices((provider, builder) =>
|
||||
{
|
||||
var configuration = provider.GetRequiredService<IConfiguration>();
|
||||
var connString = configuration.GetConnectionString("bb");
|
||||
builder.UsingProvider<SQLiteDatabaseProvider>()
|
||||
.UsingConnectionString(connString);
|
||||
});
|
||||
|
||||
// 增加后台任务
|
||||
services.AddTaskServices();
|
||||
|
|
Loading…
Reference in New Issue