-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom configuration via Options pattern #955
Comments
I think the overload your described On second note if there's something that is hard to get configured in Quartz via the provided configuration API it might also make sense to add typed helpers there, not sure about your use case though. |
I'm afraid I'm not familiar enough with Quartz to create a PR with a reasonable work estimate. So, sorry, not this time. I accidentally linked wrong issue regarding the feedback, it's fixed now. |
All fine, I'll see what I can do 👍 |
To clarify, here's a simple use case with strongly typed settings: .AddQuartz((serviceProvider, configurator) => {
var cron = serviceProvider
.GetRequiredService<IOptions<MyOptions>>()
.Value
.Cron;
configurator.AddTrigger(trigger => trigger
.ForJob("MyJob")
.WithCronSchedule(cron));
}); |
For file-based, auto-refreshed, schedule configuration there's also the XML option, but you have probably already checked that out too. But I see the use case for retrieving things from own configuration/service infrastructure. |
My 2-cent: adding such an overload will be very complicated, as the The use case described in @ljani's latest post would be easily solved if Quartz.NET used services.AddOptions<QuartzOptions>()
.Configure<IOptions<MyOptions>>((options, dep) =>
{
options.AddTrigger(trigger => trigger
.ForJob("MyJob")
.WithCronSchedule(dep.Value.Cron));
}); |
Thanks @kevinchalet for chiming in! I did a quick look earlier and this service provider indeed seemed quite hard to achieve. Now I need to study the options model 🙂 |
So I've done changes required to achieve @kevinchalet 's proposed idea with PR #978 . Hopefully this is nor more in line with expectations from options pattern and allows to do the Configure. |
@lahma Looks great for my needs, thanks! |
Is your feature request related to a problem? Please describe.
"I'm always frustrated when" I cannot access
IServiceProvider
in theconfigure
action ofAddQuartz
.Describe the solution you'd like
AddQuartz
should have an overload likeAddQuartz(this IServiceCollection serviceCollection, Action<IServiceProvider, IServiceCollectionQuartzConfigurator>? configure = null)
similar to eg.AddContext
.Describe alternatives you've considered
Alternatively Quartz could expose an options interface, and I could configure with eg.
IConfigureOptions<QuartzOptions>
. For exampleAddCors
does this withCorsOptions
. One can useIConfigureOptions<CorsOptions>
to configure cors and accessIServiceProvider
.As a workaround I can manually bootstrap the dependencies I'd like to access in
AddQuartz
.Additional context
My use cases are similar to Andrew Lock's described in this blog post. Hope you find some inspiration there.
Many thanks!
EDIT: To be clear, this is a minor improvement on the configuration interface as feedback was requested.
The text was updated successfully, but these errors were encountered: