Class diagram - dependency or association from cla

2019-02-25 20:50发布

问题:

I have a question regarding creating a class diagram where I have used dependency injection.

I have following code example:

public class ReservationController : ApiController
{
    private readonly IGetReservationService _getReservationService;

    public ReservationController(IGetReservationService getReservationService)
    {
        _getReservationService = getReservationService;
    }

    // GET list of all reservations
    public List<ReservationViewModel> GetReservations()
    {
        return _getReservationService.GetReservations();
    } 

    // GET single reservation by id
    public List<ReservationViewModel> GetReservation(string reservationNumber)
    {
        return _getReservationService.GetReservation(reservationNumber);
    }

}

Here you see that the controller (ReservationController) getting the IGetReservationService injected in the constructor. When creating the relationship between the controller and the interface, do you then use a dependency or an association?

My guess is that it should be a dependency since we are using dependency injection?

Good day.

回答1:

Yes, this is a dependency. An association is used if you have object references (e.g. for a property).