好吧,也许我错过了什么或非常担心......
我有一个控制器来生成我的图像。在一个页面上,它可能有 100 个或更多图像。对于生成的每个图像,都会调用 ImagingController。我使用依赖注入并注意到对于显示的每个图像,都构造了依赖类。
src="@Url.Action("Thumbnail", "Imaging")/id"
private readonly IDBAccess _dbaccess;
private readonly ILogger _logger;
private readonly ISettings _settings;
private readonly IStateManager _statemanager;
public ImagingController(IDBAccess dbaccess, ILogger logger, ISettings settings, IStateManager statemanager)
{
this._dbaccess = dbaccess;
this._logger = logger;
this._settings = settings;
this._statemanager = statemanager;
}
public ActionResult Thumbnail(int id)
{
...
return File((byte[])data, "image/jpeg");
}
因此,上述 4 个依赖类中的每一个都被构造了 100 次。这似乎有点太多开销还是我错了?