Hi. I am trying to resolve an Idbconnection from within a quartz job, but the connstring is always empty and so crashes when trying to open a db connection. What am I misunderstanding about the dbconnfactory that means the connstring is lost when IDbConnectinFactory is being resolved?
I am using @Mac 's Quartz job tool, specifically I try to resolve a service from within a Quartz job and/or create a dbconnection to query the db directly in my job.
In all my API logic (e.g. the Service endpoints), if i use my Idbconnectionfactory registration (which i believe is a singleton?), things work great.
container.Register<IDbConnectionFactory>(new OrmLiteConnectionFactory(connectionString, SqlServer2012OrmLiteDialectProvider.Instance));
But while I can resolve a service (and the idbconnetionfactory) from within a quartz job, i cannot USE the factory OR use the service (which in turn uses db connectivity), because of this missing connstring?
E.g:
public class HarvestMsEquityListingGenericInfoJob : IJob
{
// autoinjected
public HarvestMsEquityListingGeneralInfoEndpoint myService { get; set; }
// autoinjected
public IDbConnectionFactory myConnFact { get; set; }
public Task Execute(IJobExecutionContext context)
{
// both myService and myConnFact are resolved and
// injected by Funq - so far so good
// BUT ... next line fails, dbconnstring not set ???
using (var db = myConnFact.OpenDbConnection())
{
// try to get stuff from db, but can't
}
// I also tried resolving a service or an idbconnectionfactory
// from the HostContext directly, but same issue, so i think
// problem is my Funq, not Mac's library?
// same issue on next line, dbconnstring is emtpy and connection
// fails on use of harvestService.Db
// using (var harvestService = HostContext.TryResolve<HarvestMsEquityListingGeneralInfoEndpoint>())
}
}
@Mac’s project, for reference (he doesn’t do any db access, but Mac if you have had this working before, I would appreciate your comments as well?)