Skip to content

Commit 7775410

Browse files
committed
Formatting.
1 parent 6381396 commit 7775410

22 files changed

Lines changed: 226 additions & 173 deletions

File tree

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using Microsoft.EntityFrameworkCore;
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using Microsoft.EntityFrameworkCore;
24

35
namespace TodoList.ApiService.Model;
46

57
public class ApplicationDbContext : DbContext
68
{
7-
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
8-
: base(options) { }
9+
public ApplicationDbContext( DbContextOptions<ApplicationDbContext> options )
10+
: base( options ) { }
911

1012
public DbSet<Todo> Todos { get; set; } = null!;
11-
}
13+
}
Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
13
using Microsoft.Data.Sqlite;
24
using Microsoft.EntityFrameworkCore;
35
using TodoList.ApiService.Model;
46
using TodoList.ApiService.Services;
57

6-
var builder = WebApplication.CreateBuilder(args);
8+
var builder = WebApplication.CreateBuilder( args );
79

810
// Add service defaults & Aspire components.
911
builder.AddServiceDefaults();
@@ -38,47 +40,56 @@
3840
await db.Database.EnsureCreatedAsync();
3941
}
4042

41-
app.MapGet( "/todo", ( TodoService todos, CancellationToken cancellationToken )
42-
=> todos.GetTodosAsync( cancellationToken ) );
43-
44-
app.MapGet( "/todo/{id}", ( TodoService todos, int id, CancellationToken cancellationToken )
45-
=> todos.GetTodoAsync( id, cancellationToken ) );
43+
app.MapGet(
44+
"/todo",
45+
( TodoService todos, CancellationToken cancellationToken )
46+
=> todos.GetTodosAsync( cancellationToken ) );
4647

47-
app.MapPost( "/todo", async ( TodoService todos, Todo todo, CancellationToken cancellationToken ) =>
48-
{
49-
var newTodo = await todos.AddTodoAsync( todo, cancellationToken );
50-
return Results.Created( $"/todo/{newTodo.Id}", newTodo );
51-
} );
52-
53-
app.MapPut( "/todo/{id}", async ( TodoService todos, int id, Todo todo, CancellationToken cancellationToken ) =>
54-
{
55-
if ( id != todo.Id )
56-
{
57-
return Results.BadRequest( "The ID in the URL does not match the ID in the request body." );
58-
}
48+
app.MapGet(
49+
"/todo/{id}",
50+
( TodoService todos, int id, CancellationToken cancellationToken )
51+
=> todos.GetTodoAsync( id, cancellationToken ) );
5952

60-
if ( await todos.UpdateTodoAsync( todo, cancellationToken ) )
53+
app.MapPost(
54+
"/todo",
55+
async ( TodoService todos, Todo todo, CancellationToken cancellationToken ) =>
6156
{
62-
return Results.NoContent();
57+
var newTodo = await todos.AddTodoAsync( todo, cancellationToken );
6358

64-
}
65-
else
66-
{
67-
return Results.NotFound();
68-
}
69-
} );
59+
return Results.Created( $"/todo/{newTodo.Id}", newTodo );
60+
} );
7061

71-
app.MapDelete( "/todo/{id}", async ( TodoService todos, int id, CancellationToken cancellationToken ) =>
72-
{
73-
if ( await todos.DeleteTodoAsync( id, cancellationToken ) )
62+
app.MapPut(
63+
"/todo/{id}",
64+
async ( TodoService todos, int id, Todo todo, CancellationToken cancellationToken ) =>
7465
{
75-
return Results.NoContent();
76-
77-
}
78-
else
66+
if ( id != todo.Id )
67+
{
68+
return Results.BadRequest( "The ID in the URL does not match the ID in the request body." );
69+
}
70+
71+
if ( await todos.UpdateTodoAsync( todo, cancellationToken ) )
72+
{
73+
return Results.NoContent();
74+
}
75+
else
76+
{
77+
return Results.NotFound();
78+
}
79+
} );
80+
81+
app.MapDelete(
82+
"/todo/{id}",
83+
async ( TodoService todos, int id, CancellationToken cancellationToken ) =>
7984
{
80-
return Results.NotFound();
81-
}
82-
} );
83-
84-
app.Run();
85+
if ( await todos.DeleteTodoAsync( id, cancellationToken ) )
86+
{
87+
return Results.NoContent();
88+
}
89+
else
90+
{
91+
return Results.NotFound();
92+
}
93+
} );
94+
95+
app.Run();

src/aspire/logging-metalama/TodoList/TodoList.Api/Services/TodoService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.EntityFrameworkCore;
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using Microsoft.EntityFrameworkCore;
24
using TodoList.ApiService.Model;
35

46
namespace TodoList.ApiService.Services;
@@ -12,6 +14,7 @@ public partial class TodoService( ApplicationDbContext db )
1214
[Log]
1315
public async Task<Todo?> GetTodoAsync( int id, CancellationToken cancellationToken = default )
1416
=> await db.Todos.FindAsync( id );
17+
1518
// [<endsnippet LogUsingAttribute>]
1619

1720
public async Task<Todo> AddTodoAsync( Todo todo, CancellationToken cancellationToken = default )
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
22

3+
using Projects;
4+
35
var builder = DistributedApplication.CreateBuilder( args );
46

5-
var api = builder.AddProject<Projects.TodoList_Api>( "todolist-api" );
7+
var api = builder.AddProject<TodoList_Api>( "todolist-api" );
68

7-
builder.AddProject<Projects.TodoList_Web>("todolist-web" )
9+
builder.AddProject<TodoList_Web>( "todolist-web" )
810
.WithExternalHttpEndpoints()
911
.WithReference( api );
1012

11-
12-
builder.Build().Run();
13+
builder.Build().Run();
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
using Metalama.Framework.Fabrics;
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using Metalama.Framework.Fabrics;
24
using Metalama.Framework.Code;
35

46
// [<snippet Fabric>]
57
internal class LogAllPublicMethodsFabric : TransitiveProjectFabric
68
{
7-
public override void AmendProject( IProjectAmender amender ) =>
8-
amender
9+
public override void AmendProject( IProjectAmender amender )
10+
=> amender
911
.SelectTypes()
1012
.Where( type => type.Accessibility == Accessibility.Public )
1113
.SelectMany( type => type.Methods )
1214
.Where( method => method.Accessibility == Accessibility.Public && method.Name != "ToString" )
1315
.AddAspectIfEligible<LogAttribute>();
1416
}
17+
1518
// [<endsnippet Fabric>]

src/aspire/logging-metalama/TodoList/TodoList.Aspects/LogAttribute.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Metalama.Extensions.DependencyInjection;
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using Metalama.Extensions.DependencyInjection;
24
using Metalama.Framework.Aspects;
35
using Metalama.Framework.Code;
46
using Metalama.Framework.Code.SyntaxBuilders;
@@ -12,9 +14,9 @@ public class LogAttribute : OverrideMethodAspect
1214
[IntroduceDependency]
1315
private readonly ILogger _logger;
1416

15-
public override void BuildEligibility(IEligibilityBuilder<IMethod> builder)
17+
public override void BuildEligibility( IEligibilityBuilder<IMethod> builder )
1618
{
17-
base.BuildEligibility(builder);
19+
base.BuildEligibility( builder );
1820

1921
// We cannot introduce dependencies to static classes.
2022
builder.DeclaringType().MustNotBeStatic();
@@ -55,7 +57,7 @@ public override void BuildEligibility(IEligibilityBuilder<IMethod> builder)
5557
// Display the success message. The message is different when the method is void.
5658
var successMessage = BuildInterpolatedString( true );
5759
ExpressionBuilder arguments;
58-
var isVoid = meta.Target.Method.GetAsyncInfo().ResultType.Is( typeof( void ) );
60+
var isVoid = meta.Target.Method.GetAsyncInfo().ResultType.Is( typeof(void) );
5961

6062
if ( isVoid )
6163
{
@@ -77,6 +79,7 @@ public override void BuildEligibility(IEligibilityBuilder<IMethod> builder)
7779
arguments = BuildArguments( true, true );
7880
}
7981
}
82+
8083
this._logger.LogTrace( (string) successMessage.ToValue(), (object?[]) arguments.ToValue()! );
8184
}
8285
}
@@ -96,7 +99,6 @@ public override void BuildEligibility(IEligibilityBuilder<IMethod> builder)
9699
failureMessage.AddText( " failed: " );
97100
failureMessage.AddExpression( e.Message );
98101

99-
100102
this._logger.LogWarning( (string) failureMessage.ToValue(), (object?[]) arguments.ToValue()! );
101103
}
102104
}
@@ -120,12 +122,12 @@ private static InterpolatedStringBuilder BuildInterpolatedString( bool includeOu
120122
// Include a placeholder for each parameter.
121123
foreach ( var p in meta.Target.Parameters )
122124
{
123-
if (!isFirst)
125+
if ( !isFirst )
124126
{
125127
stringBuilder.AddText( ", " );
126128
}
127129

128-
stringBuilder.AddText($"{{{p.Name}}}");
130+
stringBuilder.AddText( $"{{{p.Name}}}" );
129131

130132
isFirst = false;
131133
}
@@ -135,17 +137,20 @@ private static InterpolatedStringBuilder BuildInterpolatedString( bool includeOu
135137
return stringBuilder;
136138
}
137139

138-
private static ExpressionBuilder BuildArguments(bool includeOutParameters = false, bool includeResult = false, bool isResultRedacted = false)
140+
private static ExpressionBuilder BuildArguments(
141+
bool includeOutParameters = false,
142+
bool includeResult = false,
143+
bool isResultRedacted = false )
139144
{
140145
var arguments = new ExpressionBuilder();
141-
arguments.AppendVerbatim("[");
146+
arguments.AppendVerbatim( "[" );
142147
var isFirst = true;
143148

144149
foreach ( var p in meta.Target.Parameters )
145150
{
146-
if (!isFirst)
151+
if ( !isFirst )
147152
{
148-
arguments.AppendVerbatim(", ");
153+
arguments.AppendVerbatim( ", " );
149154
}
150155

151156
if ( SensitiveParameterFilter.IsSensitive( p ) )
@@ -167,24 +172,25 @@ private static ExpressionBuilder BuildArguments(bool includeOutParameters = fals
167172
isFirst = false;
168173
}
169174

170-
if (includeResult)
175+
if ( includeResult )
171176
{
172-
if (!isFirst)
177+
if ( !isFirst )
173178
{
174-
arguments.AppendVerbatim(", ");
179+
arguments.AppendVerbatim( ", " );
175180
}
176181

177-
if (isResultRedacted)
182+
if ( isResultRedacted )
178183
{
179-
arguments.AppendVerbatim("\"<redacted>\"");
184+
arguments.AppendVerbatim( "\"<redacted>\"" );
180185
}
181186
else
182187
{
183-
arguments.AppendVerbatim("result");
188+
arguments.AppendVerbatim( "result" );
184189
}
185190
}
186191

187-
arguments.AppendVerbatim("]");
192+
arguments.AppendVerbatim( "]" );
193+
188194
return arguments;
189195
}
190196
}

src/aspire/logging-metalama/TodoList/TodoList.Aspects/LoggingRecursionGuard.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public static class LoggingRecursionGuard
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
public static class LoggingRecursionGuard
24
{
35
[ThreadStatic]
46
public static bool IsLogging;
@@ -12,6 +14,7 @@ public static DisposeCookie Begin()
1214
else
1315
{
1416
IsLogging = true;
17+
1518
return new DisposeCookie( true );
1619
}
1720
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[AttributeUsage( AttributeTargets.Parameter | AttributeTargets.ReturnValue )]
2-
public sealed class NotLoggedAttribute : Attribute
3-
{
4-
}
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
[AttributeUsage( AttributeTargets.Parameter | AttributeTargets.ReturnValue )]
4+
public sealed class NotLoggedAttribute : Attribute { }

src/aspire/logging-metalama/TodoList/TodoList.Aspects/SensitiveParameterFilter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Metalama.Framework.Aspects;
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using Metalama.Framework.Aspects;
24
using Metalama.Framework.Code;
35

46
[CompileTime]

src/aspire/logging-metalama/TodoList/TodoList.Aspects/TodoList.Aspects.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Metalama.Extensions.DependencyInjection" Version="2024.2.15-rc" />
12-
<PackageReference Include="Metalama.Framework" Version="2024.2.15-rc" />
11+
<PackageReference Include="Metalama.Extensions.DependencyInjection" Version="$(MetalamaExtensionsVersion)" />
1312
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
1413
</ItemGroup>
1514

0 commit comments

Comments
 (0)