Skip to content

Commit 972f0d0

Browse files
committed
Update EmptyServerless templates to use annotations, and remove preview messaging from annotations template
1 parent 3c00e9b commit 972f0d0

File tree

24 files changed

+1052
-178
lines changed

24 files changed

+1052
-178
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
{
2-
"display-name": "Annotations Framework",
2+
"display-name": "Annotations Framework Sample",
33
"system-name": "Annotations",
4-
"description": "(Preview) Use the .NET Lambda Annotations framework to write Lambda Functions.",
4+
"description": "Use the .NET Lambda Annotations framework to write Lambda Functions. This is a sample application demonstrating usage of the annotations framework, as opposed to an empty project template.",
55
"sort-order": 120,
66
"hidden-tags": [
77
"C#",
88
"ServerlessProject"
99
],
1010
"tags": [
11-
"Container",
12-
"Annotations",
13-
"Preview"
11+
"Annotations"
1412
]
1513
}

Blueprints/BlueprintDefinitions/vs2022/AnnotationsFramework/template/.template.config/template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"Lambda",
66
"Serverless"
77
],
8-
"name": "Lambda Annotations Framework (Preview)",
8+
"name": "Lambda Annotations Framework",
99
"identity": "AWS.Lambda.Serverless.Annotations.CSharp",
1010
"groupIdentity": "AWS.Lambda.Serverless.Annotations",
1111
"shortName": "serverless.Annotations",

Blueprints/BlueprintDefinitions/vs2022/AnnotationsFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
1616
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.6.0" />
1717
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
18-
<PackageReference Include="Amazon.Lambda.Annotations" Version="0.13.2" />
18+
<PackageReference Include="Amazon.Lambda.Annotations" Version="0.13.5" />
1919
</ItemGroup>
2020
<ItemGroup>
2121
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace BlueprintBaseName._1
2+
{
3+
/// <summary>
4+
/// The implementation of <see cref="ICalculatorService"/>
5+
/// that will be used by our Lambda functions.
6+
/// </summary>
7+
public class CalculatorService : ICalculatorService
8+
{
9+
/// <inheritdoc/>
10+
public int Add(int x, int y)
11+
{
12+
return x + y;
13+
}
14+
15+
/// <inheritdoc/>
16+
public int Subtract(int x, int y)
17+
{
18+
return x - y;
19+
}
20+
21+
/// <inheritdoc/>
22+
public int Multiply(int x, int y)
23+
{
24+
return x * y;
25+
}
26+
27+
/// <inheritdoc/>
28+
public int Divide(int x, int y)
29+
{
30+
return x / y;
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace BlueprintBaseName._1
2+
{
3+
/// <summary>
4+
/// An interface for a service that implements the business logic of our Lambda functions
5+
/// </summary>
6+
public interface ICalculatorService
7+
{
8+
/// <summary>
9+
/// Adds x and y together
10+
/// </summary>
11+
/// <param name="x">Addend</param>
12+
/// <param name="y">Addend</param>
13+
/// <returns>Sum of x and y</returns>
14+
int Add(int x, int y);
15+
16+
/// <summary>
17+
/// Subtracts y from x
18+
/// </summary>
19+
/// <param name="x">Minuend</param>
20+
/// <param name="y">Subtrahend</param>
21+
/// <returns>x - y</returns>
22+
int Subtract(int x, int y);
23+
24+
/// <summary>
25+
/// Multiplies x and y
26+
/// </summary>
27+
/// <param name="x">Multiplicand</param>
28+
/// <param name="y">Multiplier</param>
29+
/// <returns>x * y</returns>
30+
int Multiply(int x, int y);
31+
32+
/// <summary>
33+
/// Divides x by y
34+
/// </summary>
35+
/// <param name="x">Dividend</param>
36+
/// <param name="y">Divisor</param>
37+
/// <returns>x / y</returns>
38+
int Divide(int x, int y);
39+
}
40+
}

Blueprints/BlueprintDefinitions/vs2022/AnnotationsFramework/template/src/BlueprintBaseName.1/Functions.cs

Lines changed: 86 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,36 @@ namespace BlueprintBaseName._1;
1212
public class Functions
1313
{
1414
/// <summary>
15-
/// Default constructor.
15+
/// A collection of sample Lambda functions that provide a REST API for doing simple math calculations.
1616
/// </summary>
1717
public Functions()
1818
{
19-
}
19+
private ICalculatorService _calculatorService;
2020

21-
/// <summary>
22-
/// Root route that provides information about the other requests that can be made.
23-
/// </summary>
24-
/// <returns>API descriptions.</returns>
25-
[LambdaFunction()]
26-
[HttpApi(LambdaHttpMethod.Get, "/")]
27-
public string Default()
28-
{
29-
var docs = @"Lambda Calculator Home:
21+
/// <summary>
22+
/// Default constructor.
23+
/// </summary>
24+
/// <remarks>
25+
/// The <see cref="ICalculatorService"/> implementation that we
26+
/// instantiated in <see cref="Startup"/> will be injected here.
27+
///
28+
/// As an alternative, a dependency could be injected into each
29+
/// Lambda function handler via the [FromServices] attribute.
30+
/// </remarks>
31+
public Functions(ICalculatorService calculatorService)
32+
{
33+
_calculatorService = calculatorService;
34+
}
35+
36+
/// <summary>
37+
/// Root route that provides information about the other requests that can be made.
38+
/// </summary>
39+
/// <returns>API descriptions.</returns>
40+
[LambdaFunction()]
41+
[HttpApi(LambdaHttpMethod.Get, "/")]
42+
public string Default()
43+
{
44+
var docs = @"Lambda Calculator Home:
3045
You can make the following requests to invoke other Lambda functions perform calculator operations:
3146
/add/{x}/{y}
3247
/subtract/{x}/{y}
@@ -36,59 +51,68 @@ public string Default()
3651
return docs;
3752
}
3853

39-
/// <summary>
40-
/// Perform x + y
41-
/// </summary>
42-
/// <param name="x"></param>
43-
/// <param name="y"></param>
44-
/// <returns>Sum of x and y.</returns>
45-
[LambdaFunction()]
46-
[HttpApi(LambdaHttpMethod.Get, "/add/{x}/{y}")]
47-
public int Add(int x, int y, ILambdaContext context)
48-
{
49-
context.Logger.LogInformation($"{x} plus {y} is {x + y}");
50-
return x + y;
51-
}
54+
/// <summary>
55+
/// Perform x + y
56+
/// </summary>
57+
/// <param name="x"></param>
58+
/// <param name="y"></param>
59+
/// <returns>Sum of x and y.</returns>
60+
[LambdaFunction()]
61+
[HttpApi(LambdaHttpMethod.Get, "/add/{x}/{y}")]
62+
public int Add(int x, int y, ILambdaContext context)
63+
{
64+
var sum = _calculatorService.Add(x, y);
5265

53-
/// <summary>
54-
/// Perform x - y.
55-
/// </summary>
56-
/// <param name="x"></param>
57-
/// <param name="y"></param>
58-
/// <returns>x subtract y</returns>
59-
[LambdaFunction()]
60-
[HttpApi(LambdaHttpMethod.Get, "/subtract/{x}/{y}")]
61-
public int Subtract(int x, int y, ILambdaContext context)
62-
{
63-
context.Logger.LogInformation($"{x} subtract {y} is {x - y}");
64-
return x - y;
65-
}
66+
context.Logger.LogInformation($"{x} plus {y} is {sum}");
67+
return sum;
68+
}
6669

67-
/// <summary>
68-
/// Perform x * y.
69-
/// </summary>
70-
/// <param name="x"></param>
71-
/// <param name="y"></param>
72-
/// <returns>x multiply y</returns>
73-
[LambdaFunction()]
74-
[HttpApi(LambdaHttpMethod.Get, "/multiply/{x}/{y}")]
75-
public int Multiply(int x, int y, ILambdaContext context)
76-
{
77-
context.Logger.LogInformation($"{x} multiply {y} is {x * y}");
78-
return x * y;
79-
}
70+
/// <summary>
71+
/// Perform x - y.
72+
/// </summary>
73+
/// <param name="x"></param>
74+
/// <param name="y"></param>
75+
/// <returns>x subtract y</returns>
76+
[LambdaFunction()]
77+
[HttpApi(LambdaHttpMethod.Get, "/subtract/{x}/{y}")]
78+
public int Subtract(int x, int y, ILambdaContext context)
79+
{
80+
var difference = _calculatorService.Subtract(x, y);
8081

81-
/// <summary>
82-
/// Perform x / y.
83-
/// </summary>
84-
/// <param name="x"></param>
85-
/// <param name="y"></param>
86-
/// <returns>x divide y</returns>
87-
[LambdaFunction()]
88-
[HttpApi(LambdaHttpMethod.Get, "/divide/{x}/{y}")]
89-
public int Divide(int x, int y, ILambdaContext context)
90-
{
91-
context.Logger.LogInformation($"{x} divide {y} is {x / y}");
92-
return x / y;
82+
context.Logger.LogInformation($"{x} subtract {y} is {difference}");
83+
return difference;
84+
}
85+
86+
/// <summary>
87+
/// Perform x * y.
88+
/// </summary>
89+
/// <param name="x"></param>
90+
/// <param name="y"></param>
91+
/// <returns>x multiply y</returns>
92+
[LambdaFunction()]
93+
[HttpApi(LambdaHttpMethod.Get, "/multiply/{x}/{y}")]
94+
public int Multiply(int x, int y, ILambdaContext context)
95+
{
96+
var product = _calculatorService.Multiply(x, y);
97+
98+
context.Logger.LogInformation($"{x} multiplied by {y} is {product}");
99+
return product;
100+
}
101+
102+
/// <summary>
103+
/// Perform x / y.
104+
/// </summary>
105+
/// <param name="x"></param>
106+
/// <param name="y"></param>
107+
/// <returns>x divide y</returns>
108+
[LambdaFunction()]
109+
[HttpApi(LambdaHttpMethod.Get, "/divide/{x}/{y}")]
110+
public int Divide(int x, int y, ILambdaContext context)
111+
{
112+
var quotient = _calculatorService.Divide(x, y);
113+
114+
context.Logger.LogInformation($"{x} divided by {y} is {quotient}");
115+
return quotient;
116+
}
93117
}
94118
}

0 commit comments

Comments
 (0)