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

Support for DI? #295

Open
ghost opened this issue Jan 5, 2021 · 4 comments
Open

Support for DI? #295

ghost opened this issue Jan 5, 2021 · 4 comments

Comments

@ghost
Copy link

ghost commented Jan 5, 2021

Hi,

According to the documentation there is no support for DI.

https://fluentscheduler.github.io/dependency-injection/

Any advice on what should be done here?

@t-ashraf
Copy link

t-ashraf commented May 25, 2021

This is what I've done for D.I. (excuse the formatting, I copied and pasted from Github which messed it up):

JobManager.JobStart += JobManager_JobStart;
JobManager.JobEnd += JobManager_JobEnd;
JobManager.JobException += JobManager_JobException;
JobManager.UseUtcTime();
JobManager.Initialize(new JobRegistry(serviceProvider));
using System;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using FluentScheduler;
using Jobs;
    public class JobRegistry : Registry
{
    public JobRegistry(IServiceProvider serviceProvider)
    {            
        //Prevent concurrent jobs
        NonReentrantAsDefault();
        // Schedule PerformanceMonitor once per hour
        Schedule(() => {
                var rootScope = serviceProvider.GetAutofacRoot();
                // Note, if you call 'return nestedScope.Resolve<PerformanceMonitor>();' then FluentScheduler will call Execute, but it won't Dispose any objects. Hence the using statement below and I'm manually calling Execute on the IJob implementation. 
                using(var nestedScope = rootScope.BeginLifetimeScope()) {
                     nestedScope.Resolve<PerformanceMonitor>().Execute();
                }
        }).ToRunNow().AndEvery(60).Minutes();
    }}

@dev-greene
Copy link

dev-greene commented Aug 5, 2021

I'm using IMediatr for DI. Pretty standard setup as far as that is concerned.
Then I use Mediatr calls dispatched on a schedule as I outlined in a post over here:

@phoenixcoded20
Copy link

NonReentrantAsDefault();

@t-ashraf why set this? cant we run parallel when its DI?

@t-ashraf
Copy link

t-ashraf commented Jun 1, 2023

@phoenixcoded20 - You can run in parallel when it's DI. This is just something we do because pretty much every one of our jobs uses our database and do not wish to see any of these: https://learn.microsoft.com/en-us/dotnet/api/system.data.entity.infrastructure.dbupdateconcurrencyexception?view=entity-framework-6.2.0

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants