28 lines
771 B
C#
28 lines
771 B
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace MAX.Framework.DependencyInjection
|
|
{
|
|
public static class FreeSqlDB
|
|
{
|
|
public static IServiceCollection AddFreeSqlDB(this IServiceCollection services)
|
|
{
|
|
Func<IServiceProvider, IFreeSql> fsqlFactory = r =>
|
|
{
|
|
var config = r.GetRequiredService<IConfiguration>();
|
|
var connection = config.GetConnectionString("DefaultConnection");
|
|
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
|
.UseConnectionString(FreeSql.DataType.MySql, connection)
|
|
.UseAdoConnectionPool(true)
|
|
.Build();
|
|
return fsql;
|
|
};
|
|
services.AddSingleton<IFreeSql>(fsqlFactory);
|
|
return services;
|
|
}
|
|
}
|
|
}
|