我正在尝试在Global.asax
文件中实现依赖注入。以下是代码 -
public class MvcApplication : System.Web.HttpApplication
{
private readonly IJobTimerBS _objTimer;
// want to replace this constructor injection code. How ????
//public MvcApplication(IJobTimerBS jobTimerBS)
//{
// _objTimer = jobTimerBS;
//}
protected void Application_Start()
{
UnityConfig.RegisterComponents();
processingTimer_Elapsed();
}
void processingTimer_Elapsed()
{
_objTimer.QuoteDeleteJobTimer();
}
}
业务层中的代码 -
public class JobTimerBS : IJobTimerBS
{
private readonly IUnitofWork _unitOfWork;
private IJobTimerRepository _jobTimerRepository;
public JobTimerBS(IJobTimerRepository jobTimerRepository, IUnitofWork unitOfWork)
{
_unitOfWork = unitOfWork;
_jobTimerRepository = jobTimerRepository;
_jobTimerRepository.UnitOfWork = unitOfWork;
}
public void QuoteDeleteJobTimer()
{
_jobTimerRepository.JobTimer();
}
}
我的问题是,当我无法使用构造函数注入时,如何在这种情况下实现依赖注入。如何实例化业务层中存在的JobTimerBS
中的Global.asax
类。