Does linking a service to another service lead to bad practice?

I have a C # MVC application that I break as follows: View -> Controller -> Service -> Repository

I use the subtle controller practice with each view having a unique view model that returns from the corresponding service.

Quick example: View: / NewAppointment / Step1

Its controller will look like this:

public ActionResult Step1()
{
  return View(_appointmentService.Step1GetModel() );
}

And the destination service level will look like this:

public Step1Model Step1GetModel()
{
  return new Step1Model();
}

Thus, I have several different service levels used in my application, each of which implements a separate interface.

, , . , ?

:

, . , :

, , GetCustomer .

:

 private ICustomerService _customerService;
 private IAppointmentService _appointmentService;

 public ActionResult Step1()
 {
   var viewModel = _appointmentService.Step1GetModel( _customerService );
   return View(viewModel);
 }

, .

:

private ICustomerService _customerService;
private IAppointmentService _appointmentService;

public ActionResult Step1()
{
    var customer = _customerService.GetCustomer();
    var viewModel = _appointmentService.Step1GetModel( customer );
    return View(viewModel);
}

, . , . , .

- , ?

~

+5
1

, , services - view models. , , -, , -.

, :

public ActionResult Step1()
{
    var customer = _customerService.GetCustomer();
    var appointment = _appointmentService.GetAppointmentFor(customer);

    var viewModel = new Step1ViewModel(customer, appointment);

    return View(viewModel);
}

, , , , , .

, ...

, , , . , - ORM, - :

public MyController(IUnitOfWork unitOfWork)...

public ActionResult Step1()
{
    var customer = unitOfWork.Find<Customer>();
    var viewModel = new Step1ViewModel(customer.Appointment);
    return View(viewModel);
}

, , .

+6

All Articles