1

I have a Controller class and inside it, I use multiple services. For example: when I add a new Employee, I need to add also an account for him. For this, i use EmployeeService and AccountService in EmployeeController. It's ok? Or is better to use in EmployeeService the AccountDAO and there, I add the account?

andy
  • 51
  • 1
  • 5
  • 2
    This smells like business logic and that should not be in a controller. A controller should only be a small integration layer from the web to your business services it should not contain business logic. Either let your `EmployeeService` create the account using the `AccountService`, that way everything will also execute in a single transaction. You can also use events and fire a `EmployeeCreated[Event]` and then have a listener which creates an `Account`. These are just 2 options (and opinions) on solving that problem. Key is your controller should be as thin as possible. – M. Deinum May 15 '15 at 15:19

1 Answers1

2

Technical it is ok. But I would recommend not to put any business logic into the controller.

In my opinion the EmployeeService should be responsible to create an Account when it creates the Employee.

Ralph
  • 118,862
  • 56
  • 287
  • 383