You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace NFine.Repository
  7. {
  8. /// <summary>
  9. /// 操作数据库工厂
  10. /// </summary>
  11. public class DataFactory
  12. {
  13. private static readonly Object locker = new Object();
  14. private static Database db = null;
  15. /// <summary>
  16. /// 获取指定的数据库连接
  17. /// </summary>
  18. /// <param name="connString"></param>
  19. /// <returns></returns>
  20. public static IDatabase Database(string connString)
  21. {
  22. //在并发时,使用单一对象
  23. if (db == null)
  24. {
  25. return db = new Database(connString);
  26. }
  27. else
  28. {
  29. lock (locker)
  30. {
  31. return db;
  32. }
  33. }
  34. }
  35. /// <summary>
  36. /// 获取指定的数据库连接
  37. /// </summary>
  38. /// <returns></returns>
  39. public static IDatabase Database()
  40. {
  41. return Database("Framework_SqlServer");
  42. }
  43. }
  44. }