How to organize services in Ember in right way?


#1

I have the component Schedule and call it like:

    {{schedule-show currentSupplier=supplier currentVisitor=visitor}}

This component retrives Events of Supplier and draw this events on the calendar. The component has actions to manipulate with events.

I want to encapsulate all business-logic for actions with events in the service Event. This service should depends on current supplier, current visitor, current event. The service is singleton so when one of models is changed I need to change it in the service.

For example, I need property canEdit I to check:

  • if the current user is an admin return true OR
  • if the current user is a visitor and visitor owns the current event OR
  • if the current user is a supplier and supplier owns the current event OR

I have CurrentUser service and I can inject it to Event service.

But how to inject current event to the service in right way?

For example, I need method create. To create the event I need pass current state of the form to the service also I need the currentSupplier and currentVisitor. In this case I could pass as arguments of method.

The service has finite number of dependencies. What is the right way to inject dependencies like that?

I think in methods I could make in next way:

    create(properties) {
      this.setPropeties(properties);
      doSomeLogic.............
    }

For computed properties

    property(name, properties) {
        this.setPropeties(properties);
        return this.get(name);
    }

But in this case I couldn’t create alias property in the component.