Exemplo n.º 1
0
        //private BackgroundJobServer _server;
        public HangfireWorker(IConfiguration configuration, INotificationJobService notificationJobService, ILogger <HangfireWorker> logger)
        {
            _configuration          = configuration;
            _notificationJobService = notificationJobService;
            _logger = logger;

            var builder = new ContainerBuilder();

            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();
            serviceCollection.BuildServiceProvider();
            builder.Populate(serviceCollection);
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json")
                         .Build();

            var loggerConfig = new LoggerConfiguration()
                               .ReadFrom.Configuration(config);

            builder.RegisterSerilog(loggerConfig); //(@"C:\Logs\autofac");
            //builder.RegisterType<IHttpClientFactory>();
            builder.RegisterType <EmailService>().As <IEmailService>();
            builder.RegisterType <HangfireJobService>();
            builder.RegisterType <NotificationJobService>();

            var container = builder.Build();

            //var factory = container.Resolve<IHttpClientFactory>();

            GlobalConfiguration.Configuration.UseAutofacActivator(container, false);
            GlobalConfiguration.Configuration.UseSqlServerStorage(_configuration.GetConnectionString("Hangfire"));
        }
 public WeatherForecastController(ILogger <WeatherForecastController> logger, IBackgroundJobClient backgroundJobClient, INotificationJobService notificationJobService)
 {
     _logger = logger;
     _backgroundJobClient    = backgroundJobClient;
     _notificationJobService = notificationJobService;
 }