using FreeSql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Fuel.Application;

namespace Fuel.Infrastructure
{
    public static class FreeSqlExtensions
    {
        public static void AddFreeSql(this IServiceCollection services, IConfiguration configuration)
        {
            var connectionString = configuration.GetConnectionString("MysqlConnection");
            var fsql = new FreeSqlBuilder()
                .UseConnectionString(DataType.MySql, connectionString)
                .UseAutoSyncStructure(true) // 自动同步数据库结构
                .Build();

            services.AddSingleton<IFreeSql>(fsql);
            services.AddSingleton<EntityHelper>(sp => new EntityHelper(fsql));
        }
    }
}
