public static void AddSqlServerDbProvider(this ContainerBuilder builder) { IConfiguration configruration = App.Configuration; var options = new DbProviderOptions(); // SQL Server Runtime Provider. builder.Register <SqlDbServiceProvider>() .As <IDbServiceProvider>() .As <IDbTransactionProvider>() .OnActivating((c, p) => { if (!string.IsNullOrEmpty(p.Named <string>("ConnectionString"))) { return(new SqlDbServiceProvider(p.Named <string>("ConnectionString"))); } else if (!string.IsNullOrEmpty(options.ConnectionStringName)) { return(new SqlDbServiceProvider(configruration["connectionStrings/" + options.ConnectionStringName])); } throw new ArgumentException("Database Connection String is not initialized."); }); builder.Register <SqlDbQueryStrategyProvider>().As <IDbQueryStrategyProvider>(); builder.Register <SqlDbParamChainProvider>().As <IDbParamChainProvider>().AsSingleInstance(); builder.Register <SqlDbQueryExpressionMemberNameParserProvider>().As <IDbQueryExpressionMemberNameParserProvider>().AsSingleInstance(); builder.Register <SqlDbQueryExpressionParserProvider>().As <IDbQueryExpressionParserProvider>().AsSingleInstance(); builder.Register <SqlDbTypeFinderProvider>().As <IDbTypeFinderProvider>().AsSingleInstance(); builder.Register <SqlDbSchemaStrategyProvider>().As <IDbSchemaStrategyProvider>(); builder.Register <SqlDbQueryAddExpressionNode>().As <IDbQueryExpressionNode>(); builder.Register <SqlDbEnumTableInspectorStrategy>().As <IDbEnumTableInspectorStrategy>(); builder.Register <SqlDbTableInspectorStrategy>().As <IDbTableInspectorStrategy>(); }
public static IServiceCollection AddDbProvider( this IServiceCollection services, Action <IDbProviderOptions> setupAction) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (setupAction == null) { throw new ArgumentNullException(nameof(setupAction)); } var options = new DbProviderOptions(); setupAction.Invoke(options); services.AddSingleton <IStore>(new Store(options.Configuration)); return(services); }
public static void Set(DbProviderOptions options, IList <Type> tableMaps = null, bool autoCreateTable = false) { DbProviderManager.Set(options); //注入覆盖 var provider = DbProviderManager.Get(options.Name); provider.AddService <IPageProvider, SqlitePageProvider>(); provider.AddService <IMigrateProvider, SqliteMigrateProvider>(); //表映射配置 if (tableMaps != null && tableMaps.Count > 0) { EntityUtil.SetMaps(tableMaps, options.Name); } //自动创建表 if (autoCreateTable) { var sqlMapper = new SqlMapper(options.Name); var migrate = sqlMapper.Migrate(); migrate.Init(sqlMapper); migrate.CreateTable(); } }
public static IServiceCollection AddWangSql(this IServiceCollection services, DbProviderOptions option) { DbProviderManager.Set(option); services.AddScoped <ISqlMapper, SqlMapper>(); services.AddScoped <ISqlExe, SqlMapper>(); return(services); }