1
I have an application that was developed in the DDD standard, which uses dependency injection, it works normally, however I needed to add a Windows Service type project that will start the application, the problem is that if I make a reference to my MVC controller (where the whole process is initiated) Dependency Injection does not work (the variables that reference the classes of the other layers are not loaded and are null) I believe it is pq when I do this the global file.asax (where is the injection mapping not performed), I wonder if through my windows service I can start the MVC project as a whole? I believe that this way will work the other functionalities.
Controller of the MVC:
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
}
I couldn’t understand what you mean by startar an application. Are you referring to the host startar the application pool? Access a Controller Action? What’s the point of this?
– Leandro Angelo
Within my controler I have an Index method, which I would like to run so that when I call it through windows service, dependencies are not loaded, so calls to the other error layered methods, I believe that this occurs because when called the method of another application, the configurations that of the dependency injection that is in the global.asax is not executed, so I wanted to know if it has how to execute the MVC in general, I was able to explain what I want?
– Jhonatas Silva