-
Notifications
You must be signed in to change notification settings - Fork 406
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
Consider changing documentation to avoid parameterless constructor pitfall #131
Comments
@tallesl the first thing I thought was the new() constraint in the generic too. But thinking twice i think this is not a good solution. |
I don't have too strong opinions about this, but my thoughts are that the construction of the job object should not be done by FluentScheduler. Since the construction logic is job-specific, FluentScheduler cannot reasonably know how to construct the object. Requiring a parameterless constructor for this seems kind of hacky to me. This is why I think using the other two scheduling methods are a better approach. With those, the caller handles the construction logic either by passing an existing object or a lambda/action/factory that FluentScheduler can use to construct one without knowing how it will be done. |
On a related note, I just messed up using Perhaps you could consider adding a |
Sorry for the long delay! You guys are absolutely right, it totally slipped my mind all the use cases that Thanks for being so attentive and correcting me. It's not much, but I added a remark on
Someone made a pull request of exactly that (#115). |
Just published on nuget.org, version 5.2.0. |
The documentation suggests scheduling jobs using the
.Schedule<T>()
method. This method has a common pitfall though: IfT
does not have a parameterless constructor, aSystem.MissingMethodException
will be thrown at runtime.In my case, I just broke a job during refactoring because I added a constructor that took a parameter to it and forgot/was unaware that FluentScheduler was responsible for initializing it through reflection. Since no compile-time error was raised, I did not notice my mistake before the exception was thrown at runtime.
To avoid this pitfall, I suggest these changes:
Change the documentation to suggest the compile-time safe
.Schedule(Action)
and/orSchedule(IJob)
methods instead of the.Schedule<T>()
method.Document this pitfall for the
.Schedule<T>()
method.The text was updated successfully, but these errors were encountered: