Skip to content

Commit a51456c

Browse files
authored
Change output binding model
This commit changes how output bindings are defined. There can now be only 1 output binding at the method level. The data returned from the function is used for that. For multiple output bindings, the properties inside the returned type needs to have output binding attributes
1 parent dce2216 commit a51456c

File tree

69 files changed

+1167
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1167
-172
lines changed

NuGet.Config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<configuration>
33
<packageSources>
44
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
5+
<add key="azure_app_service" value="https://www.myget.org/F/azure-appservice/api/v2" />
56
</packageSources>
67
</configuration>

extensions/Worker.Extensions.Abstractions/FunctionNameAttribute.cs renamed to extensions/Worker.Extensions.Abstractions/FunctionAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
namespace Microsoft.Azure.Functions.Worker.Extensions.Abstractions
77
{
88
[AttributeUsage(AttributeTargets.Method)]
9-
public class FunctionNameAttribute : Attribute
9+
public class FunctionAttribute : Attribute
1010
{
11-
public FunctionNameAttribute(string name)
11+
public FunctionAttribute(string name)
1212
{
1313
Name = name;
1414
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
55

66
namespace Microsoft.Azure.Functions.Worker.Extensions.Abstractions
77
{
8-
[AttributeUsage(AttributeTargets.Method)]
8+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
99
public abstract class OutputBindingAttribute : BindingAttribute
1010
{
11+
public OutputBindingAttribute()
12+
{
13+
}
14+
1115
public OutputBindingAttribute(string name)
1216
{
1317
Name = name;
1418
}
1519

16-
public string Name { get; }
20+
public string? Name { get; }
1721
}
1822
}

extensions/Worker.Extensions.CosmosDB/CosmosDBOutputAttribute.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ namespace Microsoft.Azure.Functions.Worker.Extensions.CosmosDB
77
{
88
public sealed class CosmosDBOutputAttribute : OutputBindingAttribute
99
{
10+
/// <summary>
11+
/// Constructs a new instance.
12+
/// </summary>
13+
/// <param name="databaseName">The CosmosDB database name.</param>
14+
/// <param name="collectionName">The CosmosDB collection name.</param>
15+
public CosmosDBOutputAttribute(string databaseName, string collectionName)
16+
{
17+
DatabaseName = databaseName;
18+
CollectionName = collectionName;
19+
}
20+
1021
/// <summary>
1122
/// Constructs a new instance.
1223
/// </summary>

extensions/Worker.Extensions.Storage/Blobs/BlobOutputAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
@@ -13,7 +13,7 @@ public sealed class BlobOutputAttribute : OutputBindingAttribute
1313
/// <summary>Initializes a new instance of the <see cref="BlobOutputAttribute"/> class.</summary>
1414
/// <param name="name">The name of the property to which to bind</param>
1515
/// <param name="blobPath">The path of the blob to which to bind.</param>
16-
public BlobOutputAttribute(string name, string blobPath) : base(name)
16+
public BlobOutputAttribute(string blobPath)
1717
{
1818
_blobPath = blobPath;
1919
}

extensions/Worker.Extensions.Storage/Queues/QueueOutputAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
@@ -10,7 +10,7 @@ public sealed class QueueOutputAttribute : OutputBindingAttribute
1010
{
1111
private readonly string _queueName;
1212

13-
public QueueOutputAttribute(string name, string queueName) : base(name)
13+
public QueueOutputAttribute(string queueName)
1414
{
1515
_queueName = queueName;
1616
}

samples/FunctionApp/Function1/Function1.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ namespace FunctionApp
1515
{
1616
public static class Function1
1717
{
18-
19-
[FunctionName("Function1")]
20-
[QueueOutput("book", "functionstesting2", Connection = "AzureWebJobsStorage")]
21-
public static HttpResponseData Run(
18+
[Function("Function1")]
19+
public static MyOutputType Run(
2220
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
2321
[BlobInput("test-samples/sample1.txt", Connection = "AzureWebJobsStorage")] string myBlob, FunctionContext context)
2422
{
@@ -31,14 +29,25 @@ public static HttpResponseData Run(
3129
response.Headers.Add("Content", "Content - Type: text / html; charset = utf - 8");
3230
response.WriteString("Book Sent to Queue!");
3331

34-
return response;
32+
return new MyOutputType()
33+
{
34+
Book = bookVal,
35+
HttpReponse = response
36+
};
37+
}
38+
39+
public class MyOutputType
40+
{
41+
[QueueOutput("functionstesting2", Connection = "AzureWebJobsStorage")]
42+
public Book Book { get; set; }
43+
44+
public HttpResponseData HttpReponse { get; set; }
3545
}
3646

3747
public class Book
3848
{
3949
public string name { get; set; }
4050
public string id { get; set; }
4151
}
42-
4352
}
4453
}

samples/FunctionApp/Function2/Function2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace FunctionApp
99
{
1010
public static class Function2
1111
{
12-
[FunctionName("Function2")]
12+
[Function("Function2")]
1313
public static Book Run([QueueTrigger("functionstesting2", Connection = "AzureWebJobsStorage")] Book myQueueItem,
1414
[BlobInput("test-samples/sample1.txt", Connection = "AzureWebJobsStorage")] string myBlob)
1515
{

samples/FunctionApp/Function3/Function3.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@ namespace FunctionApp
1313
{
1414
public static class Function3
1515
{
16-
17-
[FunctionName("Function3")]
18-
[QueueOutput("name", "functionstesting2", Connection = "AzureWebJobsStorage")]
19-
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
16+
[Function("Function3")]
17+
public static MyOutputType Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
2018
FunctionContext context)
2119
{
2220
var response = req.CreateResponse(HttpStatusCode.OK);
2321
response.WriteString("Success!");
2422

25-
context.OutputBindings["name"] = "some name";
26-
27-
return response;
23+
return new MyOutputType()
24+
{
25+
Name = "some name",
26+
HttpReponse = response
27+
};
2828
}
2929
}
3030

31+
public class MyOutputType
32+
{
33+
[QueueOutput("functionstesting2", Connection = "AzureWebJobsStorage")]
34+
public string Name { get; set; }
35+
36+
public HttpResponseData HttpReponse { get; set; }
37+
}
3138
}

samples/FunctionApp/Function4/Function4.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ namespace FunctionApp
1414
{
1515
public static class Function4
1616
{
17-
18-
[FunctionName("Function4")]
17+
[Function("Function4")]
1918
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, FunctionContext executionContext)
2019
{
2120
var logger = executionContext.GetLogger("FunctionApp.Function4");

0 commit comments

Comments
 (0)