类图-从类到接口的依赖关系或关联关系? [英] Class diagram - dependency or association from class to interface?
问题描述
我有一个关于在使用依赖注入的情况下创建类图的问题。
I have a question regarding creating a class diagram where I have used dependency injection.
我有以下代码示例:
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);
}
}
在这里,您看到控制器( ReservationController)将IGetReservationService注入构造函数中。在控制器和接口之间创建关系时,您是使用依赖关系还是关联关系?
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?
美好的一天。
推荐答案
是的,这是一个依赖项。如果您有对象引用(例如,用于属性),则使用关联。
Yes, this is a dependency. An association is used if you have object references (e.g. for a property).
这篇关于类图-从类到接口的依赖关系或关联关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!