Skip to content

Commit c3376be

Browse files
committed
Merge branch 'dev'
2 parents 3cb73f3 + 7e1f386 commit c3376be

File tree

26 files changed

+978
-119
lines changed

26 files changed

+978
-119
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": "Sample application demonstrating how to use the Lambda Annotations framework.",
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 Sample",
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
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="1.0.0" />
1919
</ItemGroup>
20+
<!--
21+
The FrameworkReference is used to reduce the deployment bundle size by not having to include
22+
dependencies like Microsoft.Extensions.DependencyInjection. The Microsoft.AspNetCore.App
23+
which is available in the Managed .NET Lambda runtime already includes those assemblies.
24+
-->
2025
<ItemGroup>
2126
<FrameworkReference Include="Microsoft.AspNetCore.App" />
2227
</ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@ namespace BlueprintBaseName._1;
1111
/// </summary>
1212
public class Functions
1313
{
14+
private ICalculatorService _calculatorService;
15+
1416
/// <summary>
1517
/// Default constructor.
1618
/// </summary>
17-
public Functions()
19+
/// <remarks>
20+
/// The <see cref="ICalculatorService"/> implementation that we
21+
/// instantiated in <see cref="Startup"/> will be injected here.
22+
///
23+
/// As an alternative, a dependency could be injected into each
24+
/// Lambda function handler via the [FromServices] attribute.
25+
/// </remarks>
26+
public Functions(ICalculatorService calculatorService)
1827
{
28+
_calculatorService = calculatorService;
1929
}
2030

2131
/// <summary>
@@ -46,8 +56,10 @@ public string Default()
4656
[HttpApi(LambdaHttpMethod.Get, "/add/{x}/{y}")]
4757
public int Add(int x, int y, ILambdaContext context)
4858
{
49-
context.Logger.LogInformation($"{x} plus {y} is {x + y}");
50-
return x + y;
59+
var sum = _calculatorService.Add(x, y);
60+
61+
context.Logger.LogInformation($"{x} plus {y} is {sum}");
62+
return sum;
5163
}
5264

5365
/// <summary>
@@ -60,8 +72,10 @@ public int Add(int x, int y, ILambdaContext context)
6072
[HttpApi(LambdaHttpMethod.Get, "/subtract/{x}/{y}")]
6173
public int Subtract(int x, int y, ILambdaContext context)
6274
{
63-
context.Logger.LogInformation($"{x} subtract {y} is {x - y}");
64-
return x - y;
75+
var difference = _calculatorService.Subtract(x, y);
76+
77+
context.Logger.LogInformation($"{x} subtract {y} is {difference}");
78+
return difference;
6579
}
6680

6781
/// <summary>
@@ -74,8 +88,10 @@ public int Subtract(int x, int y, ILambdaContext context)
7488
[HttpApi(LambdaHttpMethod.Get, "/multiply/{x}/{y}")]
7589
public int Multiply(int x, int y, ILambdaContext context)
7690
{
77-
context.Logger.LogInformation($"{x} multiply {y} is {x * y}");
78-
return x * y;
91+
var product = _calculatorService.Multiply(x, y);
92+
93+
context.Logger.LogInformation($"{x} multiplied by {y} is {product}");
94+
return product;
7995
}
8096

8197
/// <summary>
@@ -88,7 +104,9 @@ public int Multiply(int x, int y, ILambdaContext context)
88104
[HttpApi(LambdaHttpMethod.Get, "/divide/{x}/{y}")]
89105
public int Divide(int x, int y, ILambdaContext context)
90106
{
91-
context.Logger.LogInformation($"{x} divide {y} is {x / y}");
92-
return x / y;
107+
var quotient = _calculatorService.Divide(x, y);
108+
109+
context.Logger.LogInformation($"{x} divided by {y} is {quotient}");
110+
return quotient;
93111
}
94112
}

0 commit comments

Comments
 (0)