Home > Net >  The CORE ASP.NET MVC below this code has a problem? If there should be how to modify.
The CORE ASP.NET MVC below this code has a problem? If there should be how to modify.

Time:03-06

Public static IServiceCollection AddSqlSugar (this IServiceCollection services, ConnectionConfig [] configs, Action BuildAction=default) {
ServiceDescriptor ServiceDescriptor=services. FirstOrDefault (s=& gt; Typeof (ISqlSugarClient)==s.S erviceType);
SqlSugarClient SqlSugarClient=null;
if (null !=serviceDescriptor) sqlSugarClient=serviceDescriptor. ImplementationFactory. Invoke (services) BuildServiceProvider ()) as sqlSugarClient;

//registered SqlSugar client
Services. AddScoped (u=& gt; {
If (null==sqlSugarClient) sqlSugarClient=new sqlSugarClient (configs. ToList ());
The else Array. ForEach (configs, config=& gt; SqlSugarClient. AddConnection (config));
BuildAction? Invoke (sqlSugarClient);
Return sqlSugarClient;
});

//registered non-generic storage
Services. AddScoped (a);

//registered SqlSugar storage
Services. AddScoped (typeof (ISqlSugarRepository<>) The typeof (SqlSugarRepository<>) );

Return services;
}
  • Related