【手撸一个ORM】第九步、orm默认配置类 MyDbConfiguration,一次配置,简化实例化流程
这个实现比较简单,事实上可配置的项目很多,如有需要,请读者自行扩展
using System; namespace MyOrm { public class MyDbConfiguration { private static string _defaultConnectionString; private static string _prefix; private static bool _hasInit; public static void Init(string connectionString, string prefix = "@") { if (_hasInit) { throw new Exception("MyOrm只能初始化一次"); } _defaultConnectionString = connectionString; _prefix = prefix; _hasInit = true; } public static string GetConnectionString() { return _defaultConnectionString; } public static string GetPrefix() { return _prefix; } } }