Skip to content

Commit 52e1f59

Browse files
Adding resource for value objects and adjust GraphQL dependency injection extensions
1 parent dc9a05c commit 52e1f59

4 files changed

Lines changed: 39 additions & 25 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace Dotnet6.GraphQL4.Domain.Abstractions.ValueObjects
5+
{
6+
public abstract class ValueObject
7+
{
8+
protected static bool EqualOperator(ValueObject left, ValueObject right)
9+
=> (ReferenceEquals(left, null) ^ ReferenceEquals(right, null)) is false &&
10+
(ReferenceEquals(left, null) || left.Equals(right));
11+
12+
protected static bool NotEqualOperator(ValueObject left, ValueObject right)
13+
=> EqualOperator(left, right) is false;
14+
15+
protected abstract IEnumerable<object> GetEqualityComponents();
16+
17+
public override bool Equals(object obj)
18+
=> obj is not null && obj.GetType() == GetType() &&
19+
GetEqualityComponents().SequenceEqual(((ValueObject) obj).GetEqualityComponents());
20+
21+
public override int GetHashCode()
22+
=> GetEqualityComponents()
23+
.Select(x => x != null ? x.GetHashCode() : 0)
24+
.Aggregate((x, y) => x ^ y);
25+
}
26+
}
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1-
using System;
2-
using System.Text.Json;
1+
using System.Text.Json;
32
using System.Text.Json.Serialization;
43
using Dotnet6.GraphQL4.Store.WebAPI.Graphs;
54
using Dotnet6.GraphQL4.Store.WebAPI.Graphs.Executers;
65
using GraphQL;
76
using GraphQL.Server;
7+
using Microsoft.AspNetCore.Hosting;
88
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Hosting;
910
using Serilog;
1011

1112
namespace Dotnet6.GraphQL4.Store.WebAPI.DependencyInjection.Extensions
1213
{
1314
public static class ServiceCollectionExtensions
1415
{
15-
private static readonly Options Options = new();
16-
17-
public static IGraphQLBuilder AddApplicationGraphQL(this IServiceCollection services, Action<Options> actionOptions)
18-
{
19-
actionOptions(Options);
20-
21-
return services
16+
public static IGraphQLBuilder AddApplicationGraphQL(this IServiceCollection services)
17+
=> services
2218
.AddScoped(typeof(IGraphQLExecuter<>), typeof(StoreGraphQLExecuter<>))
2319
.AddScoped<IDocumentExecuter, StoreDocumentExecuter>()
2420
.AddSingleton<StoreSchema>()
2521
.AddGraphQL(
26-
(options, _) =>
22+
(options, serviceProvider) =>
2723
{
28-
options.EnableMetrics = Options.IsDevelopment;
24+
options.EnableMetrics = serviceProvider.GetRequiredService<IWebHostEnvironment>().IsDevelopment();
2925

3026
options.UnhandledExceptionDelegate = exceptionContext
3127
=> Log.Error(
@@ -44,11 +40,5 @@ public static IGraphQLBuilder AddApplicationGraphQL(this IServiceCollection serv
4440
.AddWebSockets()
4541
.AddDataLoader()
4642
.AddGraphTypes(typeof(StoreSchema));
47-
}
48-
}
49-
50-
public class Options
51-
{
52-
public bool IsDevelopment { get; set; }
5343
}
5444
}

src/Dotnet6.GraphQL4.Store.WebAPI/Startup.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public void Configure(IApplicationBuilder app , ILoggerFactory loggerFactory)
8282

8383
public void ConfigureServices(IServiceCollection services)
8484
{
85+
services.ConfigureTransactionOptions(_configuration.GetSection("Transactions"));
86+
services.ConfigureSqlServerRetryingOptions(_configuration.GetSection("SqlServerRetryingOptions"));
87+
8588
services
8689
.AddLogging()
8790
.AddBuilders()
@@ -92,15 +95,10 @@ public void ConfigureServices(IServiceCollection services)
9295
.AddApplicationMessageServices()
9396
.AddApplicationSubjects()
9497
.AddApplicationAutoMapper()
98+
.AddApplicationDbContext()
9599
.AddControllers();
96100

97-
services.ConfigureTransactionOptions(_configuration.GetSection("Transactions"));
98-
services.ConfigureSqlServerRetryingOptions(_configuration.GetSection("SqlServerRetryingOptions"));
99-
100-
services.AddApplicationDbContext();
101-
102-
services.AddApplicationGraphQL(options
103-
=> options.IsDevelopment = _env.IsDevelopment());
101+
services.AddApplicationGraphQL();
104102

105103
services.Configure<KestrelServerOptions>(options
106104
=> options.AllowSynchronousIO = true);

src/Dotnet6.GraphQL4.Store.WebAPI/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"MinimumLevel": {
1818
"Default": "Debug",
1919
"Override": {
20-
"Microsoft": "Warning",
20+
"Microsoft": "Information",
2121
"Microsoft.Hosting.Lifetime": "Information"
2222
}
2323
}

0 commit comments

Comments
 (0)