I have an application that was developed in the DDD standard, which uses dependency injection, it is working normally, but I needed to add a project of type Windows Service that will be the start of the application, the problem is that a reference is made my MVC controller (where I start the whole process) dependency injection does not work (the variables that make references to the classes of the other layers are not loaded and become null) I believe that is because when I do this the global file. asax (where the injection mapping is not executed), I would like to know if through my windows service I can start the MVC project as a whole? I believe this will work the other features.
MVC Controller:
private readonly IAwbApplication _awbApplication;
private readonly IMovimentoApplication _movimentoApplication;
public static List<string> LogAplicacao = new List<string>();
public AwbController(IAwbApplication awbApplication, IMovimentoApplication movimentoApplication)
{
_awbApplication = awbApplication;
_movimentoApplication = movimentoApplication;
}
public void Index()
{
try
{
var movimentos = _movimentoApplication.ObterMovimentos();
foreach (var movimento in movimentos)
{
var listaStatusWebServiceGol = _awbApplication.Pesquisar(movimento.nr_AWB.Trim()).ToList();
var listaStatusMovimento = _awbApplication.StatusPorMovimento(movimento.id_Movimento);
for (var i = listaStatusMovimento.Count(); i < listaStatusWebServiceGol.Count(); i++)
{
listaStatusWebServiceGol.ToList()[i].id_Movimento = movimento.id_Movimento;
_awbApplication.InserirMovimentoTracking(listaStatusWebServiceGol.ToList()[i]);
}
}
}
catch (Exception ex)
{
GravarLogAplicacaoValidacao(ex);
}
finally
{
var log = new GeradorLogUtil();
log.EscreverLog(LogAplicacao, @"C:\TrackingAwb\LogErro.txt");
}
}
Windows Service:
protected override void OnStart(string[] args)
{
Console.WriteLine(@"O Serviço começou");
ExecutarRotina();
// _worker = new Timer((ExecutarRotina), null, 0, _interval);
}
protected override void OnStop()
{
Console.WriteLine(@"O Serviço parou");
}
public void ExecutarRotina()
{
// preciso chamar o projeto MVC aqui
}