Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1、为AssemblyAutoRegisterOptions.SmartSqlAlias设置默认值;2、仓储接口注册时,获取ISqlMapper实例都通过IServiceProvider.EnsureSmartSql方法获取 #216

Merged
merged 2 commits into from
Feb 24, 2023

Conversation

xiangxiren
Copy link
Collaborator

在注册多数据库实例情况下,如果没有使用UseAlias()方法设置Alias时,会默认使用DEFAULT_ALIAS = "SmartSql"。但是在仓储接口实例化时,通过sp.GetRequiredService<ISqlMapper>()方法获取ISqlMapper实例就由后注册的SmartSqlDIBuilder实例提供。

services.AddSingleton<ISqlMapper>(sp => sp.GetRequiredService<SmartSqlBuilder>().SqlMapper);

因此将sp.GetRequiredService<ISqlMapper>()改成统一使用SmartSqlBuilder EnsureSmartSql(this IServiceProvider sp, string alias = SmartSqlBuilder.DEFAULT_ALIAS)方法获取ISqlMapper实例,改后的代码即:

var sqlMapper = !string.IsNullOrEmpty(options.SmartSqlAlias)
                        ? sp.EnsureSmartSql(options.SmartSqlAlias).SqlMapper
                        : sp.EnsureSmartSql().SqlMapper;

为类型AssemblyAutoRegisterOptions的属性SmartSqlAlias设置默认值,也是为了实现第一个SmartSqlDIBuilder实例注册时没有单独指定Alias的时候,也能够正确获取仓储接口实例,与上面的改动都是相同的目的。

@XiaoHeitu XiaoHeitu merged commit 1dce744 into dotnetcore:master Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants