/// <summary> /// 添加FreeSqlGen相关 /// 模板地址默认:DefaultTemplatePath = "RazorTemplate" /// sqlite持久化默认地址 SqliteDbConnectionString="Data Source=fsbuilder.db;Version=3" /// </summary> /// <param name="services"></param> /// <param name="setupAction">生成器模板配置项</param> public static void AddFreeSqlBuilder(this IServiceCollection services, Action <FreeSqlBuilderOption> setupAction = null) { var options = new FreeSqlBuilderOption(); setupAction?.Invoke(options); if (string.IsNullOrWhiteSpace(options.DbSet.ConnectionString)) { throw new Exception("ConnectionString必须填写"); } services.AddSingleton(options); //配置导入 services.AddMvc(opt => opt.EnableEndpointRouting = false) .AddNewtonsoftJson(option => option.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore) //防止递归导致json输出不正确 .AddRazorRuntimeCompilation(); //MVC动态编译 ; services.AddFreeSqlBuilderCore(); services.AddSingleton <HtmlEncoder>(NullHtmlEncoder.Default); //HTML中文编码处理 services.AddSingleton <FileProviderHelper>(); //文件相关处理 services.AddMemoryCache(); services.AddSingleton <IFreeSql <FsBuilder> >(x => { var builder = new FreeSql.FreeSqlBuilder() .UseConnectionString(dataType: options.DbSet.DbType, options.DbSet.ConnectionString) .UseAutoSyncStructure(true) .Build <FsBuilder>(); builder.Aop.CommandAfter += (s, e) => Aop_CommandAfter(s, e, x.GetService <ILogger <IFreeSql> >()); return(builder); }); //持久化 services.AddScoped <IUnitOfWork>(x => x.GetService <IFreeSql <FsBuilder> >().CreateUnitOfWork()); services.AddScoped <ReflectionHelper>(); //反射助手 services.AddScoped <BuildTask>(); //核心任务 services.AddSingleton <RazorTemplateEngine>(); //Razor模板引擎 services.AddTransient <RazorViewToStringRender>(); //Razor渲染字符串 services.AddScoped <DefaultDataInit>(); }
public ReflectionHelper(IMemoryCache cache, IFreeSql <FsBuilder> freeSql, FreeSqlBuilderOption option) { _cache = cache; _freeSql = freeSql; _option = option; }
/// <summary> /// 文件提供助手 /// </summary> /// <param name="_webEnv"></param> public FileProviderHelper(IWebHostEnvironment _webEnv, IFreeSql <FsBuilder> freeSql, FreeSqlBuilderOption options) { webEnv = _webEnv; _freeSql = freeSql; _options = options; }