/// <summary> /// Constructs Job Storage by database connection string and options /// </summary> /// <param name="connectionString">LiteDB connection string</param> /// <param name="storageOptions">Storage options</param> public LiteDbStorage(string connectionString, LiteDbStorageOptions storageOptions) { if (string.IsNullOrWhiteSpace(connectionString)) { throw new ArgumentNullException(nameof(connectionString)); } _connectionString = connectionString; _storageOptions = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions)); Connection = HangfireDbContext.Instance(connectionString, storageOptions.Prefix); Connection.Init(_storageOptions); var defaultQueueProvider = new LiteDbJobQueueProvider(_storageOptions); QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider); }
/// <summary> /// Opens connection to database /// </summary> /// <returns>Database context</returns> public HangfireDbContext CreateAndOpenConnection() { return(_connectionString != null ? HangfireDbContext.Instance(_connectionString, _storageOptions.Prefix) : null); }