SHARE
TWEET

Program.cs

a guest May 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using AT.Domain.Repositories;
  2. using AT.Persistence;
  3. using AT.Persistence.Repositories;
  4. using AT.SharedKernel.Infrastructure.Logger;
  5. using Autofac;
  6. using Microsoft.Azure.WebJobs;
  7. using Microsoft.Azure.WebJobs.Host;
  8.  
  9. namespace AT.WebJobs
  10. {
  11.     // To learn more about Microsoft Azure WebJobs SDK, please see https://go.microsoft.com/fwlink/?LinkID=320976
  12.     public class Program
  13.     {
  14.         // Please set the following connection strings in app.config for this WebJob to run:
  15.         // AzureWebJobsDashboard and AzureWebJobsStorage
  16.         static void Main()
  17.         {
  18.             var builder = new ContainerBuilder();
  19.             builder.Register(c => new CoreContext()).InstancePerDependency();
  20.             builder.RegisterType<CustomerRepository>().As<ICustomerRepository>().InstancePerRequest();
  21.             builder.RegisterType<Functions>()
  22.                 .WithParameter("customerRepository", new CustomerRepository(new Logger()))
  23.                 .SingleInstance();
  24.  
  25.             var container = builder.Build();
  26.  
  27.             var config = new JobHostConfiguration()
  28.             {
  29.                 JobActivator = new AutofacJobActivator(container)
  30.             };
  31.  
  32.             if (config.IsDevelopment)
  33.             {
  34.                 config.UseDevelopmentSettings();
  35.             }
  36.  
  37.             config.UseTimers();
  38.  
  39.             var host = new JobHost(config);
  40.             // The following code ensures that the WebJob will be running continuously
  41.             host.RunAndBlock();
  42.  
  43.         }
  44.  
  45.         public class AutofacJobActivator : IJobActivator
  46.         {
  47.             private readonly IContainer _container;
  48.  
  49.             public AutofacJobActivator(IContainer container)
  50.             {
  51.                 _container = container;
  52.             }
  53.  
  54.             public T CreateInstance<T>()
  55.             {
  56.                 return _container.Resolve<T>();
  57.             }
  58.         }
  59.  
  60.     }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top