Use the IBinder! #webjobs rock

What if you don't want to mess around with your Azure Storage Account and bother with  creating a Blob Client in your web job, but just want to be ... taken care of (as Web Jobs are so great at doing)? Well, as it turns out, it's really easy to get a hold of a Blob inside your WebJob method - just use the IBinder!

Let's read some JSON data, as an example:

public static async Task HandleMessage(..., IBinder binder)
{
  ...
  var json =
    await binder.BindAsync(
      new BlobAttribute($"{blobContainer}/{blobName}"));
  var obj = JToken.ReadFrom(new JsonTextReader(json));
  ...
}


If you know up-front which blob you want to read, bind to it directly in your method declaration.

That's it! Web Jobs rock!

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints