Skip to content
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

✨ [FEATURE] Added Auto Configurer #24

Merged
merged 8 commits into from
Jan 30, 2022

Conversation

furkandeveloper
Copy link
Owner

Summary

This PR includes added auto configurer for cron jobs.

How to use?

** Step 1

Define your cron job

** Step 2

Install EasyCronJob.AutoConfigurer nuget package

** Step 3

Configure Cron Jobs with Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.InitializeCronServices();
    services.AutoConfigurer();
}

** NOTE **
This PR includes new feature. This feature has been requested by community members.
See #23 for more information

@furkandeveloper furkandeveloper self-assigned this Jan 30, 2022
@furkandeveloper furkandeveloper added this to In progress in Feature Jan 30, 2022
@furkandeveloper furkandeveloper merged commit ab81f6b into develop Jan 30, 2022
@furkandeveloper furkandeveloper deleted the feature/auto-configurer branch January 30, 2022 14:35
private static List<Type> FindCronJobServices()
{
var baseCronJobType = typeof(CronJobService);
var cronJobServices = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend to use Assembly.GetEntryAssembly().GetReferencedAssemblies() here.

This'll ignore 2nd level references. So, unwanted registrations can be prevented.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion.
Could you give some more detailed information about the risks?
@enisn

Copy link

@enisn enisn Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an example, I'm using EasyCronJob in my library and I have a couple of CronJobService, but I only register only one of them. Or I'm configuring them according to a condition, my code picks one of my CronJobService and registers it according to a condition.

If your application has that autoconfiguration and depends on my library, you'll register all of my CronJobServices in my library and all app domain assemblies too, even if I don't want to register all of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Feature
In progress
Development

Successfully merging this pull request may close these issues.

Have the ICronConfiguration load from the appsettings ✨ [FEATURE]
2 participants