Доколкото знам, webjob няма заявката. Той просто изпълнява програми като фонови процеси в App Service Web Apps. Не можа да получи заявката.
По мое мнение инстанцирането на Per Request Lifetime се използва в уеб приложения като ASP.NET уеб формуляри и MVC приложения, а не уеб задания.
Какво имаш предвид с молбата?
Обикновено ще използваме екземпляра за зависимост в уеб задачите, като използваме AutofacJobActivator.
Той автоматично ще създаде нов екземпляр, когато функцията се задейства.
Ето пример за уеб работа:
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 =>
{
var model = new DeltaResponse();
return model;
})
.As<IDropboxApi>()
.SingleInstance();
builder.RegisterType<Functions>().InstancePerDependency();
var Container = builder.Build();
var config = new JobHostConfiguration()
{
JobActivator = new AutofacJobActivator(Container)
};
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>();
}
}
public interface IDropboxApi
{
void GetDelta();
}
public class DeltaResponse : IDropboxApi
{
public Guid id { get; set; }
public DeltaResponse()
{
id = Guid.NewGuid();
}
void IDropboxApi.GetDelta()
{
Console.WriteLine(id);
//throw new NotImplementedException();
}
}
Functions.cs:
public class Functions
{
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
private readonly IDropboxApi _dropboxApi;
public Functions(IDropboxApi dropboxApi)
{
_dropboxApi = dropboxApi;
}
public void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
log.WriteLine("started");
// Define request parameters.
_dropboxApi.GetDelta();
}
}
Когато функцията се задейства, тя автоматично ще създаде нов екземпляр.
person
Brando Zhang
schedule
17.08.2017