26
loading...
This website collects cookies to deliver better user experience
dotnet --version
code . -r
<TargetFramework>net5.0</TargetFramework>
namespace azure_function_entities.models
{
public record Output(string Message, string ApiKey);
}
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.3" OutputItemType="Analyzer"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.3.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.0.1" />
</ItemGroup>
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
using azure_function_managers.services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Reflection;
namespace azure_function
{
public class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration(options => options.AddUserSecrets(assembly: Assembly.GetExecutingAssembly(), optional: true, reloadOnChange: true))
.ConfigureServices(services => services.AddScoped<IGreetingsService, GreetingsService>())
.Build();
host.Run();
}
}
}
using System;
using azure_function_entities.models;
using azure_function_managers.services;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace azure_function
{
public class TimerTriggerFunc
{
private readonly IGreetingsService _greetingsService;
private readonly IConfiguration _configuration;
public TimerTriggerFunc(IGreetingsService greetingsService, IConfiguration configuration)
{
_greetingsService = greetingsService;
_configuration = configuration;
}
[Function("TimerTriggerFunc")]
public void Run([TimerTrigger("%TimerCron%")] TimerInfo myTimer, FunctionContext context)
{
var logger = context.GetLogger<TimerTriggerFunc>();
logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
Output output = new(_greetingsService.SayHello("ivan"), _configuration.GetValue<string>("ApiKey"));
logger.LogInformation($"Message: {output.Message}");
logger.LogInformation($"ApiKey: {output.ApiKey}");
}
public class TimerInfo
{
public ScheduleStatus ScheduleStatus { get; set; }
public bool IsPastDue { get; set; }
}
public class ScheduleStatus
{
public DateTime Last { get; set; }
public DateTime Next { get; set; }
public DateTime LastUpdated { get; set; }
}
}
}
using Microsoft.Azure.Functions.Worker;
that allow us to use "isolated" process features.Microsoft.Azure.WebJobs
.