⚙️ Services

In Velora, Services contain the business logic of your application. They should not depend on HTTP or controllers directly. Services are injected into controllers using Velora’s dependency injection system powered by dig.Container.

🛠️ Creating a Service

A typical service is a simple struct with methods. Example:

package user

type Service struct{}

func NewService() *Service {
    return &Service{}
}

func (s *Service) FindAll() []string {
    return []string{"Alice", "Bob", "Charlie"}
}

🔌 Dependency Injection

Services are registered in the DI container inside the module’sRegister function:

func (m *UserModule) Register(container *dig.Container, app *fiber.App) error {
    container.Provide(NewService) // make Service injectable
    return nil
}

Now, controllers can automatically receive the service as a dependency.

🚀 Best Practices

  • Keep services independent from HTTP (no fiber.Ctx inside services).
  • Write unit tests for services separately.
  • Use services to implement core domain logic, reusable across controllers.