如果我误解了一些基本知识,请忍受,但是...
假设Controller需要几个依赖项注入服务,例如DBContext,AutoMapper,也许还有其他一些注册的服务(当然已经在Startup类中正确注册了),可以吗?
单个注入服务的伪代码:
class MyController
{
private DBContext _context;
MyController(DBContext context)
{
_context = context;
}
}
但是如果我需要多种服务,例如(再次是伪代码):
class My2ndController
{
private DBContext _context;
private IMapper _mapper;
private SomeConfig _config;
My2ndController(DBContext context,IMapper mapper,SomeConfig config)
{
_context = context;
_mapper = mapper;
_config = config;
}
}
有可能吗?