DB.cs 901 B

123456789101112131415161718192021222324252627282930
  1. using Microsoft.Extensions.DependencyInjection;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace DAL
  9. {
  10. public static class DB
  11. {
  12. public static ISqlSugarClient SqlSugarClient { get; set; }
  13. public static void AddSqlSugarSetup(this IServiceCollection services, SqlSugar.DbType dataType, string conn)
  14. {
  15. if (services == null) throw new ArgumentNullException(nameof(services));
  16. services.AddSingleton<ISqlSugarClient>(s =>
  17. {
  18. SqlSugarClient = new SqlSugarScope(new ConnectionConfig()
  19. {
  20. DbType = dataType,
  21. ConnectionString = conn,
  22. IsAutoCloseConnection = true
  23. });
  24. return SqlSugarClient;
  25. });
  26. }
  27. }
  28. }