Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using AT.Domain.Repositories;
- using AT.Persistence;
- using AT.Persistence.Repositories;
- using AT.SharedKernel.Infrastructure.Logger;
- using Autofac;
- using Microsoft.Azure.WebJobs;
- using Microsoft.Azure.WebJobs.Host;
- namespace AT.WebJobs
- {
- // To learn more about Microsoft Azure WebJobs SDK, please see https://go.microsoft.com/fwlink/?LinkID=320976
- public class Program
- {
- // Please set the following connection strings in app.config for this WebJob to run:
- // AzureWebJobsDashboard and AzureWebJobsStorage
- static void Main()
- {
- var builder = new ContainerBuilder();
- builder.Register(c => new CoreContext()).InstancePerDependency();
- builder.RegisterType<CustomerRepository>().As<ICustomerRepository>().InstancePerRequest();
- builder.RegisterType<Functions>()
- .WithParameter("customerRepository", new CustomerRepository(new Logger()))
- .SingleInstance();
- var container = builder.Build();
- var config = new JobHostConfiguration()
- {
- JobActivator = new AutofacJobActivator(container)
- };
- if (config.IsDevelopment)
- {
- config.UseDevelopmentSettings();
- }
- config.UseTimers();
- var host = new JobHost(config);
- // The following code ensures that the WebJob will be running continuously
- host.RunAndBlock();
- }
- public class AutofacJobActivator : IJobActivator
- {
- private readonly IContainer _container;
- public AutofacJobActivator(IContainer container)
- {
- _container = container;
- }
- public T CreateInstance<T>()
- {
- return _container.Resolve<T>();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement