public static SmartSqlOptions UseOptions(this SmartSqlOptions smartSqlOptions, IServiceProvider sp) { var configLoader = BuildConfigLoader(sp, smartSqlOptions.ConfigPath); smartSqlOptions.ConfigLoader = configLoader; return(smartSqlOptions); }
private static void InitOptions(IServiceProvider sp, SmartSqlOptions options) { if (String.IsNullOrEmpty(options.ConfigPath)) { var env = sp.GetService <IHostingEnvironment>(); if (env != null && !env.IsProduction()) { options.ConfigPath = $"SmartSqlMapConfig.{env.EnvironmentName}.xml"; } if (!File.Exists(options.ConfigPath)) { options.ConfigPath = Consts.DEFAULT_SMARTSQL_CONFIG_PATH; } } if (String.IsNullOrEmpty(options.Alias)) { options.Alias = options.ConfigPath; } if (options.LoggerFactory == null) { options.LoggerFactory = sp.GetService <ILoggerFactory>(); } if (options.ConfigLoader == null) { options.ConfigLoader = sp.GetService <IConfigLoader>(); } }
public PreparedCommand_Test() { _smartSqlOptions = new SmartSqlOptions(); _smartSqlOptions.Setup(); _sessionStore = _smartSqlOptions.DbSessionStore; _preparedCommand = new PreparedCommand(LoggerFactory.CreateLogger <PreparedCommand>(), _smartSqlOptions.SmartSqlContext); }
public CommandExecuter_Test() { _smartSqlOptions = new SmartSqlOptions(); _smartSqlOptions.Setup(); _sessionStore = _smartSqlOptions.DbSessionStore; _commandExecuter = new CommandExecuter(LoggerFactory.CreateLogger <CommandExecuter>(), _smartSqlOptions.PreparedCommand); }
private static IProcessEngineBuilder AddSmartSqlMapper(this IProcessEngineBuilder builder) { builder.Services.AddSingleton <ISmartSqlMapper>(sp => { var codebase = AppDomain.CurrentDomain.BaseDirectory; IDataSource dataSource = sp.GetService <IDataSource>(); var dbSessionStore = new DbConnectionSessionStore(sp.GetService <ILoggerFactory>(), dataSource.DbProviderFactory); SmartSqlOptions options = new SmartSqlOptions { ConfigPath = Path.Combine(codebase, DEFAULT_MYBATIS_MAPPING_FILE), DbSessionStore = dbSessionStore }; SmartSqlMapper ssm = new SmartSqlMapper(options); options.SmartSqlContext.Settings.IsWatchConfigFile = true; options.SmartSqlContext.Database.WriteDataSource.ConnectionString = dataSource.ConnectionString; foreach (var ds in options.SmartSqlContext.Database.ReadDataSources) { ds.ConnectionString = dataSource.ConnectionString; } return(ssm); }); return(builder); }
public static ISmartSqlMapper Create(CreateSmartSqlMapperOptions options) { var smartSqlDbProvider = DbProviders.GetDbProvider(options.ProviderName); SmartSqlConfigOptions smartSqlConfigOptions = new SmartSqlConfigOptions { Settings = new SmartSql.Configuration.Settings { ParameterPrefix = "$", IgnoreParameterCase = true, IsWatchConfigFile = false, IsCacheEnabled = false, }, Database = new Database { DbProvider = smartSqlDbProvider, Write = options.DataSource, Read = new List <SmartSql.Configuration.ReadDataSource>() }, SmartSqlMaps = new List <SmartSql.Configuration.SmartSqlMapSource>(), TypeHandlers = new List <SmartSql.Configuration.TypeHandler> { new SmartSql.Configuration.TypeHandler { Name = "Json", Type = "SmartSql.TypeHandler.JsonTypeHandler,SmartSql.TypeHandler" }, new SmartSql.Configuration.TypeHandler { Name = "PGJson", Type = "SmartSql.TypeHandler.PostgreSql.JsonTypeHandler,SmartSql.TypeHandler.PostgreSql" }, new SmartSql.Configuration.TypeHandler { Name = "PGJsonb", Type = "SmartSql.TypeHandler.PostgreSql.JsonbTypeHandler,SmartSql.TypeHandler.PostgreSql" }, new SmartSql.Configuration.TypeHandler { Name = "OracleBoolean", Type = "SmartSql.TypeHandler.Oracle.BooleanTypeHandler,SmartSql.TypeHandler.Oracle" } } }; if (!String.IsNullOrEmpty(options.SqlMapPath)) { smartSqlConfigOptions.SmartSqlMaps.Add(new SmartSql.Configuration.SmartSqlMapSource { Path = options.SqlMapPath, Type = SmartSql.Configuration.SmartSqlMapSource.ResourceType.Directory }); } var _configLoader = new OptionConfigLoader(smartSqlConfigOptions, options.LoggerFactory); var smartsqlOptions = new SmartSqlOptions { Alias = options.Alias, ConfigPath = options.Alias, ConfigLoader = _configLoader, LoggerFactory = options.LoggerFactory }; return(MapperContainer.Instance.GetSqlMapper(smartsqlOptions)); }
public void Setup() { _dataRowParserFactory = new DataRowParserFactory(); var smartSqlOptions = new SmartSqlOptions { }; _sqlMapper = new SmartSqlMapper(smartSqlOptions); }
public SqlBuilder_Test() { _sqlBuilder = new SqlBuilder(LoggerFactory.CreateLogger <SqlBuilder>()); _smartSqlOptions = new SmartSqlOptions { SqlBuilder = _sqlBuilder }; _smartSqlOptions.Setup(); }
public EmitDataReaderDeserializer_Test() { _deserializerFactory = new EmitDataReaderDeserializerFactory(); _smartSqlOptions = new SmartSqlOptions { DataReaderDeserializerFactory = _deserializerFactory }; _smartSqlOptions.Setup(); _sessionStore = _smartSqlOptions.DbSessionStore; _commandExecuter = new CommandExecuter(LoggerFactory.CreateLogger <CommandExecuter>(), _smartSqlOptions.PreparedCommand); }
/// <summary> /// 注入默认 ISmartSqlMapper /// </summary> /// <param name="services"></param> public static void AddSmartSql(this IServiceCollection services) { services.AddSingleton(sp => { var options = new SmartSqlOptions(); InitOptions(sp, options); return(MapperContainer.Instance.GetSqlMapper(options)); }); AddOthers(services); }
public void Setup() { _dataRowParserFactory = new DataRowParserFactory(); var smartSqlOptions = new SmartSqlOptions { ConfigPath = Consts.DEFAULT_SMARTSQL_CONFIG_PATH }; _sqlMapper = new SmartSqlMapper(smartSqlOptions); }
public static void AddSmartSql(this IServiceCollection services) { services.AddSingleton <ISmartSqlMapper>(sp => { var options = new SmartSqlOptions { LoggerFactory = sp.GetService <ILoggerFactory>() }; return(MapperContainer.Instance.GetSqlMapper(options)); }); AddOthers(services); }
public void Setup(SmartSqlOptions smartSqlOptions) { SmartSqlContext = smartSqlOptions.SmartSqlContext; SetupStatement(); SetupParameters(); SetupMap(); if (Items == null) { Items = new Dictionary <object, object>(); } smartSqlOptions.SqlBuilder.BuildSql(this); SetupKey(); }
private void InitSqlMapper() { if (!_dbProviders.TryGetValue(DbProviderName, out SmartSql.Configuration.DbProvider smartSqlDbProvider)) { var supportDbProviders = String.Join(",", _dbProviders.Select(m => m.Key)); var errMsg = $"Can not find DbProvider:{DbProviderName},SmartCode support DbProviders:{supportDbProviders}!"; _logger.LogError(errMsg); throw new SmartCodeException(errMsg); } SmartSqlConfigOptions smartSqlConfigOptions = new SmartSqlConfigOptions { Settings = new SmartSql.Configuration.Settings { ParameterPrefix = "$" }, Database = new Database { DbProvider = smartSqlDbProvider, Write = new SmartSql.Configuration.WriteDataSource { Name = DbName, ConnectionString = ConnectionString }, Read = new List <SmartSql.Configuration.ReadDataSource>() }, SmartSqlMaps = new List <SmartSql.Configuration.SmartSqlMapSource> { new SmartSql.Configuration.SmartSqlMapSource { Path = "Maps", Type = SmartSql.Configuration.SmartSqlMapSource.ResourceType.Directory } }, TypeHandlers = new List <SmartSql.Configuration.TypeHandler>() }; var _configLoader = new OptionConfigLoader(smartSqlConfigOptions, _loggerFactory); var smartsqlOptions = new SmartSqlOptions { ConfigPath = "SmartSql", ConfigLoader = _configLoader }; SqlMapper = MapperContainer.Instance.GetSqlMapper(smartsqlOptions); }
public static void AddSmartSqlOptionLoader(this IServiceCollection services) { services.AddSingleton <IConfigLoader>((sp) => { var loggerFactory = sp.GetService <ILoggerFactory>() ?? NoneLoggerFactory.Instance; var optionsMonitor = sp.GetService <IOptionsMonitor <SmartSqlConfigOptions> >(); var _configLoader = new OptionConfigLoader(optionsMonitor.CurrentValue, loggerFactory); SmartSqlOptions smartSqlOptions = new SmartSqlOptions { ConfigLoader = _configLoader, LoggerFactory = loggerFactory }; if (optionsMonitor.CurrentValue.Settings.IsWatchConfigFile) { optionsMonitor.OnChange((ops, name) => { _configLoader.TriggerChanged(ops); }); } return(_configLoader); }); }
private void InitSqlMapper() { _dbProviders.TryGetValue(DbProviderName, out SmartSql.Configuration.DbProvider smartSqlDbProvider); SmartSqlConfigOptions smartSqlConfigOptions = new SmartSqlConfigOptions { Settings = new SmartSql.Configuration.Settings { ParameterPrefix = "$" }, Database = new SmartSql.Options.Database { DbProvider = smartSqlDbProvider, Write = new SmartSql.Configuration.WriteDataSource { Name = DbName, ConnectionString = ConnectionString }, Read = new List <SmartSql.Configuration.ReadDataSource>() }, SmartSqlMaps = new List <SmartSql.Configuration.SmartSqlMapSource> { new SmartSql.Configuration.SmartSqlMapSource { Path = "Maps", Type = SmartSql.Configuration.SmartSqlMapSource.ResourceType.Directory } }, TypeHandlers = new List <SmartSql.Configuration.TypeHandler>() }; var _configLoader = new OptionConfigLoader(smartSqlConfigOptions, _loggerFactory); var smartsqlOptions = new SmartSqlOptions { ConfigPath = "SmartSql", ConfigLoader = _configLoader }; SqlMapper = MapperContainer.Instance.GetSqlMapper(smartsqlOptions); }
public static void UserOptions(this SmartSqlOptions smartSqlOptions, IServiceProvider sp) { var _configLoader = sp.GetRequiredService <IConfigLoader>(); smartSqlOptions.ConfigLoader = _configLoader; }