1
- using Microsoft . Extensions . DependencyInjection . Extensions ;
1
+ using System ;
2
+ using System . Reflection ;
3
+ using Microsoft . Extensions . DependencyInjection . Extensions ;
2
4
using Microsoft . Extensions . Logging ;
3
- using SmartSql ;
4
5
using SmartSql . DIExtension ;
5
6
using SmartSql . DyRepository ;
6
- using System ;
7
- using System . Linq ;
8
- using System . Reflection ;
9
- using SmartSql . Exceptions ;
10
7
using SmartSql . Utils ;
11
8
12
9
namespace Microsoft . Extensions . DependencyInjection
@@ -48,13 +45,12 @@ public static SmartSqlDIBuilder AddRepositoryFactory(this SmartSqlDIBuilder buil
48
45
public static SmartSqlDIBuilder AddRepository < T > ( this SmartSqlDIBuilder builder , string smartSqlAlias , string scope = "" ) where T : class
49
46
{
50
47
builder . AddRepositoryFactory ( ) ;
51
- builder . Services . AddSingleton < T > ( sp =>
48
+ builder . Services . AddSingleton ( sp =>
52
49
{
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
+
58
54
var factory = sp . GetRequiredService < IRepositoryFactory > ( ) ;
59
55
return factory . CreateInstance ( typeof ( T ) , sqlMapper , scope ) as T ;
60
56
} ) ;
@@ -80,18 +76,17 @@ public static SmartSqlDIBuilder AddRepositoryFromAssembly(this SmartSqlDIBuilder
80
76
{
81
77
builder . Services . AddSingleton ( type , sp =>
82
78
{
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
+
88
83
var factory = sp . GetRequiredService < IRepositoryFactory > ( ) ;
89
84
var scope = string . Empty ;
90
85
if ( ! String . IsNullOrEmpty ( options . ScopeTemplate ) )
91
86
{
92
87
scope = templateParser . Parse ( type . Name ) ;
93
88
}
94
-
89
+
95
90
var instance = factory . CreateInstance ( type , sqlMapper , scope ) ;
96
91
if ( instance . IsDyRepository ( ) )
97
92
{
0 commit comments