3

For Azure functions:
Is there any difference using the Blob binding or manually creating the reference for it?

1: Binding

public Task Run(
    [HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req,
    [Blob("images")] CloudBlobContainer container)
{
    // Code
}

2: Manual

public Task Run(
    [HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
    var account = CloudStorageAccount.Parse(connectionstring);
    var client = account.CreateCloudBlobClient();
    var container = client.GetContainerReference("images");

    // Code
}

I'm only talking a difference in performance.
Is it not the exact same thing happening "under the hood" in both examples?

Rasmus
  • 225
  • 2
  • 6
  • 1
    It's ultimately the same thing but obviously the implementation is vastly different. The Microsoft documentation says it best ... *Triggers and bindings let you avoid hardcoding access to other services.* Personally, I don't think they're really any different, it's just an abstracted layer you can make use of if need be. I prefer to code the input bindings and sometimes, the output bindings as well, it depends on the scenario. That's my take on it. – Skin Apr 05 '22 at 00:07

1 Answers1

1

I believe both of the implementation gives same performance.

Yes! As Skin Said, Microsoft suggests you avoid hardcoding access to the integration services with Azure Functions.

Scenarios like when the Function is receiving or sending the data (queue message), you can use the Function Parameters for receiving data and return value of the function for sending data.

One of the practical examples, I come to know the difference and usage of this bindings and hardcode in the Azure functions from Pluralsight course is:

Here in below code, I took Blob output binding the Function level:

public class GenerateLicenseFile
{
[FunctionName("GenerateLicenseFile")]
public void Run([QueueTrigger("orders", Connection = "AzureWebJobsStorage")]Order order,
[Blob("licenses/{rand-guid}.lic")]TextWriter outputBlob,
ILogger log)
{
outputBlob.WriteLine($"OrderId: {order.OrderId}");
outputBlob.WriteLine($"Email: {order.Email}");
outputBlob.WriteLine($"ProductId: {order.ProductId}");
outputBlob.WriteLine($"PurchaseDate: {DateTime.UtcNow}");

To bring the Order Id as the license File name,

public  static  class  GenerateLicenseFile

{

[FunctionName("GenerateLicenseFile")]
public  static  async  Task  Run(
[QueueTrigger("orders", Connection  =  "AzureWebJobsStorage")] Order  order,
IBinder  binder,
ILogger  log)
{
var  outputBlob  =  await  binder.BindAsync<TextWriter>(
new  BlobAttribute($"licenses/{order.OrderId}.lic")
{
Connection  =  "AzureWebJobsStorage"
});
outputBlob.WriteLine($"OrderId: {order.OrderId}");
outputBlob.WriteLine($"Email: {order.Email}");
outputBlob.WriteLine($"ProductId: {order.ProductId}");
outputBlob.WriteLine($"PurchaseDate: {DateTime.UtcNow}");

There are some scenarios mentioned when to use bindings as parameters and hardcode in the Azure Functions, please refer this Microsoft Documentation for more information.