-
Notifications
You must be signed in to change notification settings - Fork 11
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 NCronJob access to IConfiguration #37
Comments
My current way of thinking was that the user should be responsible for all configuration and just pass down the values to us that are necessary. While I do see an appeal for the second approach (which I would prefer) I am still not totally convinced that we should push this right now. @falvarez1, can you elaborate on where this either makes our current code much simpler or allows (right now) new scenarios? |
This is mostly for paving the way to future enhancements. For example the dashboard component needs a way to provide a URI and some type of secret or access token. This would differ based on environment and infrastructure, you would want devs to have access to make changes in real-time without recompiling. Sure the developers could create their own way to push configuration into the extension methods but I think the dev experience starts to suffer. Regarding simplifying code, it wouldn't necessarily simplify the internal library code but the second option would just reduce boilerplate anywhere we would need access to IConfiguration. |
Really good thoughts and I do agree - for the time being I will flag this as „Future“. |
I moved this to |
Potential first candate: |
@linkdotnet I've update your branch for This should handle the scenario where calling the If
If 'AddNCronJob' is called from the |
How about replicating the way IServiceCollection.AddSingleton() works? There's an extension that accepts a IServiceProvider. Another option would be to split through the AddNCronJob()/UserNCronJob() pattern. |
I do like the second approach, just because it is more what people are used to! |
If that's ok with you 'm going to try and give it a go. I'll ping back with an early spike to gather feedback. |
Ah absolutely. That would be awesome. If possible, the solution should be backward compatible (semantic versioning). Otherwise, we have to target this feature for |
I've thought about that. Hence the "gather feedback" step 😉 |
@linkdotnet I followed a quick (and somewhat dirty) track that led me into an dead-end, locked in the DI lifecycle. If can think at least of two options:
Obviously, the Before diving deeper, I was willing to share my train of thoughts and get your feedback on the proposed approach (considering the timeline you might have planned for |
In both cases: How would one define dependencies between jobs? Services.AddNCronJob(s => s.AddJob<MyJob>(c => ...).ExecuteWhen(success: s => s.RunJob<AnotherJob>())); In the I am not a big fan of implicit scanning, mainly because it will probably make #54 harder in the long run and may or may not surprise people. There is no timeline for |
non breaking change option: in the same way it's currently done. breaking change version:
I agree. Not a fan of scanning either. In the end, I guess the only viable option is the |
Fair. I am inclined to put this into the backlog and tackle it when it is really needed. There are other issues that are more important than this one. But thanks for shipping in @nulltoken |
I'm interested in playing further with this idea on my spare time. I'll try to find some time to work on the Expression angled approach. |
Oh for sure! That is very nice and welcome :D |
Another use case where the .Add()/.Use() pattern may be useful has been identified in #106.
Below the initial comment
|
I will flag this one for |
FWIW I've quickly tested this approach and forgot to report here my findings. I've eventually hit a quick brick wall. Expressions don't play well with optional arguments. CS0854 An expression tree may not contain a call or invocation that uses optional arguments I'll revisit this later and see if switching to overloads may help. But that may be a tedious path... |
Objective:
Enhance the configuration process of NCronJob by proposing two new methods to integrate
IConfiguration
access into theAddNCronJob
method. This change aims to reduce boilerplate code, streamline the configuration process for developers, and lay the foundation for easily integrating future features that require configuration. By centralizing configuration access, we can more effectively manage and introduce new settings and features without disrupting the existing implementation or increasing the complexity for developers.Proposed Enhancements
Method 1: Optional Parameter (Non-breaking Change)
Introduce an optional parameter to the existing AddNCronJob method that allows passing IConfiguration explicitly. This approach maintains compatibility with current usage while offering flexibility for developers who wish to manage their configuration more directly.
Method 2: Extend WebApplicationBuilder (Breaking Change)
Propose a more integrated approach by making AddNCronJob an extension of WebApplicationBuilder. This method inherently accesses IConfiguration directly within the extension, simplifying the API and aligning with ASP.NET Core configuration practices.
The text was updated successfully, but these errors were encountered: