# File lib/openshift-origin-controller/app/models/application.rb, line 1224
  def add_dependency(dep)
    reply = ResultIO.new
    self.class.notify_observers(:before_add_dependency, {:application => self, :dependency => dep, :reply => reply})
    # Create persistent storage app entry on configure (one of the first things)
    Rails.logger.debug "DEBUG: Adding embedded app info from persistant storage: #{@name}:#{dep}"
    self.cart_data = {} if @cart_data.nil?

    raise OpenShift::UserException.new("#{dep} already embedded in '#{@name}'", 136) if self.embedded.include? dep
    if self.scalable
      allowed_cartridges = SCALABLE_EMBEDDED_CARTS & Application.get_available_cartridges.sort
      raise OpenShift::UserException.new("#{dep} cannot be embedded in scalable app '#{@name}'. Allowed cartridges: #{allowed_cartridges.join(', ')}", 108) if not SCALABLE_EMBEDDED_CARTS.include? dep
    end
    add_to_requires_feature(dep)
    begin
      reply.append self.configure_dependencies
      self.execute_connections
    rescue Exception => e
      remove_from_requires_feature(dep)
      self.elaborate_descriptor
      self.save
      raise e
    end

    self.class.notify_observers(:after_add_dependency, {:application => self, :dependency => dep, :reply => reply})
    reply
  end