Azure Functions 3.0 is now generally available, bringing .NET Core 3.1 support and significant improvements. Here’s what developers need to know.
Key Improvements
- .NET Core 3.1 Support: Run your functions on the LTS version
- Dependency Injection: First-class DI in the functions runtime
- Improved Cold Start: Faster startup times in consumption plan
- HTTP Triggered Functions: ASP.NET Core integration model
Dependency Injection Example
// Startup.cs
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddScoped<IMyService, MyService>();
builder.Services.AddHttpClient();
}
}
// Function with DI
public class MyFunction
{
private readonly IMyService _service;
public MyFunction(IMyService service) => _service = service;
[FunctionName("ProcessData")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
var result = await _service.ProcessAsync();
return new OkObjectResult(result);
}
}
Migration from 2.x
The migration is straightforward:
- Update to .NET Core 3.1
- Change target framework to
netcoreapp3.1 - Update NuGet packages to 3.x versions
- Review breaking changes in Newtonsoft.Json handling
References
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.