public override void Open() { if (dbContext == null) { lock (lockObject) { DbDirectoryContext <T> context; #if NET45 if (dbContext == null) { context = new DbDirectoryContext <T>(connectionName); context.Database.Connection.Open(); dbContext = context; } #endif #if NETCORE if (dbContext == null) { var optionsBuilder = new DbContextOptionsBuilder <DbDirectoryContext <T> >(); optionsBuilder.UseSqlServer(connectionString); context = new DbDirectoryContext <T>(optionsBuilder.Options); context.Database.OpenConnectionAsync(); dbContext = context; } #endif } } }
public DbDirectoryAccountService() { #if NET45 string url = ConfigurationManager.AppSettings["DirectoryAccountService.RootEntryPath"]; if (String.IsNullOrEmpty(url)) { throw new KeyNotFoundException("The configuration key is not found in the config file, please add 'DirectoryAccountService.RootEntryPath' to the appSettings config."); } connectionName = url.Replace("DB://", ""); dbContext = new DbDirectoryContext <T>(connectionName); #endif #if NETCORE var dir = Directory.GetCurrentDirectory(); var builder = new ConfigurationBuilder() .SetBasePath(dir) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); var configuration = builder.Build(); connectionName = configuration.GetValue <string>("DirectoryAccountService:connectionString"); connectionString = configuration.GetConnectionString(connectionName); var optionsBuilder = new DbContextOptionsBuilder <DbDirectoryContext <T> >(); optionsBuilder.UseSqlServer(connectionString); dbContext = new DbDirectoryContext <T>(optionsBuilder.Options); #endif }
public DbDirectoryService() { string url = ConfigurationManager.AppSettings["DirectoryAccountService.RootEntryPath"]; if (String.IsNullOrEmpty(url)) { throw new KeyNotFoundException("The configuration key is not found in the config file, please add 'DirectoryAccountService.RootEntryPath' to the appSettings config."); } connectionName = url.Replace("DB://", ""); dbContext = new DbDirectoryContext <T>(connectionName); }
public DbDirectoryService(string connectionName) { this.connectionName = connectionName; var dir = Directory.GetCurrentDirectory(); var builder = new ConfigurationBuilder() .SetBasePath(dir) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); var configuration = builder.Build(); var optionsBuilder = new DbContextOptionsBuilder <DbDirectoryContext <T> >(); connectionString = configuration.GetConnectionString(connectionName); optionsBuilder.UseSqlServer(connectionString); dbContext = new DbDirectoryContext <T>(optionsBuilder.Options); }
public override void Open() { if (dbContext == null) { lock (lockObject) { DbDirectoryContext <T> context; if (dbContext == null) { context = new DbDirectoryContext <T>(connectionName); context.Database.Connection.Open(); dbContext = context; } } } }
public override void Close() { if (dbContext == null) { return; } lock (dbContext) { #if NET45 dbContext.Database.Connection.Close(); #endif #if NETCORE dbContext.Database.CloseConnection(); #endif dbContext = null; } }
public DbDirectoryAccountService(DbContextOptions options) { dbContext = new DbDirectoryContext <T>(options); }
public DbDirectoryService(string connectionName) { this.connectionName = connectionName; dbContext = new DbDirectoryContext <T>(connectionName); }