1- using Microsoft . Extensions . DependencyInjection . Extensions ;
1+ using System ;
2+ using System . Reflection ;
3+ using Microsoft . Extensions . DependencyInjection . Extensions ;
24using Microsoft . Extensions . Logging ;
3- using SmartSql ;
45using SmartSql . DIExtension ;
56using SmartSql . DyRepository ;
6- using System ;
7- using System . Linq ;
8- using System . Reflection ;
9- using SmartSql . Exceptions ;
107using SmartSql . Utils ;
118
129namespace Microsoft . Extensions . DependencyInjection
@@ -48,13 +45,12 @@ public static SmartSqlDIBuilder AddRepositoryFactory(this SmartSqlDIBuilder buil
4845 public static SmartSqlDIBuilder AddRepository < T > ( this SmartSqlDIBuilder builder , string smartSqlAlias , string scope = "" ) where T : class
4946 {
5047 builder . AddRepositoryFactory ( ) ;
51- builder . Services . AddSingleton < T > ( sp =>
48+ builder . Services . AddSingleton ( sp =>
5249 {
53- ISqlMapper sqlMapper = sp . GetRequiredService < ISqlMapper > ( ) ; ;
54- if ( ! String . IsNullOrEmpty ( smartSqlAlias ) )
55- {
56- sqlMapper = sp . EnsureSmartSql ( smartSqlAlias ) . SqlMapper ;
57- }
50+ var sqlMapper = string . IsNullOrEmpty ( smartSqlAlias )
51+ ? sp . EnsureSmartSql ( ) . SqlMapper
52+ : sp . EnsureSmartSql ( smartSqlAlias ) . SqlMapper ;
53+
5854 var factory = sp . GetRequiredService < IRepositoryFactory > ( ) ;
5955 return factory . CreateInstance ( typeof ( T ) , sqlMapper , scope ) as T ;
6056 } ) ;
@@ -80,18 +76,17 @@ public static SmartSqlDIBuilder AddRepositoryFromAssembly(this SmartSqlDIBuilder
8076 {
8177 builder . Services . AddSingleton ( type , sp =>
8278 {
83- ISqlMapper sqlMapper = sp . GetRequiredService < ISqlMapper > ( ) ; ;
84- if ( ! String . IsNullOrEmpty ( options . SmartSqlAlias ) )
85- {
86- sqlMapper = sp . EnsureSmartSql ( options . SmartSqlAlias ) . SqlMapper ;
87- }
79+ var sqlMapper = string . IsNullOrEmpty ( options . SmartSqlAlias )
80+ ? sp . EnsureSmartSql ( ) . SqlMapper
81+ : sp . EnsureSmartSql ( options . SmartSqlAlias ) . SqlMapper ;
82+
8883 var factory = sp . GetRequiredService < IRepositoryFactory > ( ) ;
8984 var scope = string . Empty ;
9085 if ( ! String . IsNullOrEmpty ( options . ScopeTemplate ) )
9186 {
9287 scope = templateParser . Parse ( type . Name ) ;
9388 }
94-
89+
9590 var instance = factory . CreateInstance ( type , sqlMapper , scope ) ;
9691 if ( instance . IsDyRepository ( ) )
9792 {
0 commit comments