IModel GetModel(ITransactionContext context) { var model = context.GetOrAdd(CurrentModelItemsKey, () => { if (_models.TryDequeue(out var modelFromPool)) { if (modelFromPool.IsOpen) { context.OnDisposed(tc => _models.Enqueue(modelFromPool)); return(modelFromPool); } try { _log.Debug("Found out current model was closed... disposing it"); modelFromPool.Close(); modelFromPool.Dispose(); } catch { } } _log.Debug("Initializing new model"); var connection = _connectionManager.GetConnection(); var newModel = connection.CreateModel(); context.OnDisposed(tc => _models.Enqueue(newModel)); // Configure registered events on model _callbackOptions?.ConfigureEvents(newModel); return(newModel); });
IModel GetModel(ITransactionContext context) { var model = context.GetOrAdd(CurrentModelItemsKey, () => { var connection = _connectionManager.GetConnection(); var newModel = connection.CreateModel(); context.OnDisposed(() => newModel.Dispose()); // Configure registred events on model _callbackOptions?.ConfigureEvents(newModel); return(newModel); }); return(model); }