Closed cadilhac closed 2 years ago
You can now use it like so:
builder.Services.AddQuartz(q =>
{
// Use a Scoped container to create jobs.
q.UseMicrosoftDependencyInjectionJobFactory();
q.UsePersistentStore(storeOptions =>
{
storeOptions.UseRavenDbWithInjectedDocumentStore();
storeOptions.UseJsonSerializer();
});
// Comment out these lines and uncomment app.Lifetime.ApplicationStarted.Register(OnStarted); to make it work
q.AddJob<SampleJob>(j => j.WithIdentity("SampleJob"));
q.AddTrigger(t => t
.WithIdentity("SampleTrigger")
.ForJob("SampleJob")
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(4, 0).InTimeZone(TimeZoneInfo.Utc))
);
});
builder.Services.AddSingleton<IDocumentStore>(sp =>
{
var docStore = new DocumentStore
{
Urls = new[] { "http://localhost:8080" },
Database = "QuartzTest"
};
docStore.Initialize();
return docStore;
});
@ayende Does not work. I get:
Quartz.SchedulerException: 'JobStore of type 'Quartz.Impl.RavenDB.RavenJobStoreWithInjectDocumentStore' could not be instantiated.'
Inner exception:
ArgumentException: Cannot instantiate type which has no empty constructor (Parameter 'RavenJobStoreWithInjectDocumentStore')
Seems like there is no constructor dependency injection for stores...
@ayende Any fix for this DI issue?
Haven't dropped this, still looking into this, but finding time to actually devote to it is tough.
Mentioned the issue on the quartz.net github page.
I think reopening this issue here would be good too.
My asp.net core project already uses RavenDB.DependencyInjection, which creates a DocumentStore that is available to controllers via DI. Your library also creates a store. It would be great if it could use an injected store already created by another service. Otherwise, there are 2 stores and 2 configs to create them. In other words, how can I pass an existing IDocumentStore to this library?