Skip to content

Commit 3a2abf6

Browse files
Lots of refactoring and reordering
1 parent ac50d82 commit 3a2abf6

File tree

32 files changed

+813
-29
lines changed

32 files changed

+813
-29
lines changed

samples/DotNetElements.Samples.AppFramework.WebApi/Modules/Categories/Entities/Category.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using DotNetElements.Samples.AppFramework.WebApi.Modules.ToDoItems;
1+
using DotNetElements.AppFramework.Abstractions.Entity;
2+
using DotNetElements.Samples.AppFramework.WebApi.Modules.ToDoItems;
23

34
namespace DotNetElements.Samples.AppFramework.WebApi.Modules.Categories;
45

samples/DotNetElements.Samples.AppFramework.WebApi/Modules/ToDoItems/Entities/ToDoItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using DotNetElements.Samples.AppFramework.WebApi.Modules.Categories;
1+
using DotNetElements.AppFramework.Abstractions.Entity;
2+
using DotNetElements.Samples.AppFramework.WebApi.Modules.Categories;
23

34
namespace DotNetElements.Samples.AppFramework.WebApi.Modules.ToDoItems;
45

src/DotNetElements.AppFramework/Entity/EntityBase.cs renamed to src/DotNetElements.AppFramework.Abstractions/Entity/EntityBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace DotNetElements.AppFramework;
1+
using DotNetElements.AppFramework.Abstractions.Entity;
2+
3+
namespace DotNetElements.AppFramework;
24

35
public abstract class Entity { }
46

src/DotNetElements.AppFramework/Entity/EntityContracts.cs renamed to src/DotNetElements.AppFramework.Abstractions/Entity/EntityContracts.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace DotNetElements.AppFramework;
1+
namespace DotNetElements.AppFramework.Abstractions.Entity;
22

33
public interface IEntity<TKey> : IHasKey<TKey>
44
where TKey : notnull, IEquatable<TKey>;
@@ -57,3 +57,22 @@ public interface IUpdateFromEx<TFrom> : IUpdateFrom
5757
{
5858
void Update(TFrom from, IEntityUpdateHelper entityUpdateHelper);
5959
}
60+
61+
public interface IEntityUpdateHelper
62+
{
63+
TRelatedEntity AttachById<TRelatedEntity, TKey>(TKey id, bool checkAlreadyTracked = false)
64+
where TRelatedEntity : Entity<TKey>
65+
where TKey : notnull, IEquatable<TKey>;
66+
67+
Guid GetCurrentUserId();
68+
69+
DateTimeOffset GetUtcNow();
70+
71+
void UpdateRelatedEntities<TEntity, TKey>(List<TEntity> oldCollection, IEnumerable<TKey> newIdsCollection)
72+
where TEntity : Entity<TKey>
73+
where TKey : notnull, IEquatable<TKey>
74+
{
75+
EntityHelper.UpdateRelatedEntities<TEntity, TKey>(oldCollection, newIdsCollection, this);
76+
}
77+
}
78+

src/DotNetElements.AppFramework/Entity/EntityHelper.cs renamed to src/DotNetElements.AppFramework.Abstractions/Entity/EntityHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Runtime.CompilerServices;
22

3-
namespace DotNetElements.AppFramework;
3+
namespace DotNetElements.AppFramework.Abstractions.Entity;
44

55
public static class EntityHelper
66
{

src/DotNetElements.AppFramework.AspNet/ResultExtensions/CrudResultExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.AspNetCore.Http;
1+
using System.Linq.Expressions;
2+
using Microsoft.AspNetCore.Http;
23

34
using IHttpResult = Microsoft.AspNetCore.Http.IResult;
45

@@ -22,6 +23,14 @@ public static IHttpResult MapToHttpResult<TEntity>(this CrudResult<TEntity> crud
2223
return MapToFailedHttpResult(error.Value);
2324
}
2425

26+
public static IHttpResult MapToHttpResultWithProjection<TEntity, TResult>(this CrudResult<TEntity> crudResult, Expression<Func<TEntity, TResult>> projection)
27+
{
28+
if (crudResult.TryGetValue(out TEntity? value, out CrudError? error))
29+
return Results.Ok(projection.Compile().Invoke(value));
30+
31+
return MapToFailedHttpResult(error.Value);
32+
}
33+
2534
private static IHttpResult MapToFailedHttpResult(CrudError errorCode)
2635
{
2736
return Results.Problem(title: $"{typeof(CrudError).Name}.{errorCode}", detail: ((int)errorCode).ToString(), type: typeof(CrudError).Name);

src/DotNetElements.AppFramework.AspNet/WebApplicationBuilderExtensions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ public static WebApplicationBuilder AddAppFramework(this WebApplicationBuilder b
1717
builder.Services.AddScoped<ICurrentUserProvider, CurrentUserProvider>();
1818
builder.Services.AddSerilog((services, options) =>
1919
{
20-
options.ReadFrom.Configuration(builder.Configuration);
20+
options.ReadFrom.Configuration(builder.Configuration)
21+
.Filter.ByExcluding(logEvent => // todo only in development, make configurable
22+
{
23+
if (logEvent.Properties.TryGetValue("RequestPath", out var value))
24+
{
25+
string valueString = value.ToString();
26+
27+
return valueString.StartsWith("\"/_framework")
28+
|| valueString.StartsWith("\"/_content");
29+
}
30+
31+
return false;
32+
});
2133
});
2234

2335
builder.RegisterModules(moduleAssembly);

src/DotNetElements.AppFramework.Development/FakeCurrentUserProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace DotNetElements.AppFramework.Development;
44

5-
public class FakeCurrentUserProvider : ICurrentUserProvider
5+
public sealed class FakeCurrentUserProvider : ICurrentUserProvider
66
{
77
private readonly Guid fakeUserId;
88

src/DotNetElements.AppFramework.Example/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DotNetElements.AppFramework;
22
using DotNetElements.AppFramework.Abstractions.Auth;
3+
using DotNetElements.AppFramework.Abstractions.Entity;
34
using DotNetElements.AppFramework.Abstractions.Model;
45
using DotNetElements.AppFramework.DebugEfCore;
56
using Microsoft.Extensions.Logging;

src/DotNetElements.AppFramework.Example/TestUtils/TestAuditInterceptor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using DotNetElements.AppFramework.Abstractions.Auth;
2+
using DotNetElements.AppFramework.Abstractions.Entity;
23
using Microsoft.EntityFrameworkCore.ChangeTracking;
34
using Microsoft.EntityFrameworkCore.Diagnostics;
45

0 commit comments

Comments
 (0)