Skip to content

Commit

Permalink
Merge pull request #62 from json-api-dotnet/update-to-jadnc-v5.6.0
Browse files Browse the repository at this point in the history
Update to JADNC v5.6.0
  • Loading branch information
bkoelman authored Jun 30, 2024
2 parents 961ecef + 949b5b0 commit c26263c
Show file tree
Hide file tree
Showing 61 changed files with 279 additions and 277 deletions.
34 changes: 2 additions & 32 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,6 @@ jobs:
dotnet-version: |
6.0.x
8.0.x
- name: Setup PowerShell (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
dotnet tool install --global PowerShell
- name: Find latest PowerShell version (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$packageName = "powershell"
$outputText = dotnet tool search $packageName --take 1
$outputLine = ("" + $outputText)
$indexOfVersionLine = $outputLine.IndexOf($packageName)
$latestVersion = $outputLine.substring($indexOfVersionLine + $packageName.length).trim().split(" ")[0].trim()
Write-Output "Found PowerShell version: $latestVersion"
Write-Output "POWERSHELL_LATEST_VERSION=$latestVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Setup PowerShell (Windows)
if: matrix.os == 'windows-latest'
shell: cmd
run: |
set DOWNLOAD_LINK=https://github.com/PowerShell/PowerShell/releases/download/v%POWERSHELL_LATEST_VERSION%/PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi
set OUTPUT_PATH=%RUNNER_TEMP%\PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi
echo Downloading from: %DOWNLOAD_LINK% to: %OUTPUT_PATH%
curl --location --output %OUTPUT_PATH% %DOWNLOAD_LINK%
msiexec.exe /package %OUTPUT_PATH% /quiet USE_MU=1 ENABLE_MU=1 ADD_PATH=1 DISABLE_TELEMETRY=1
- name: Setup PowerShell (macOS)
if: matrix.os == 'macos-latest'
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install --cask powershell
- name: Show installed versions
shell: pwsh
run: |
Expand Down Expand Up @@ -235,13 +205,13 @@ jobs:
$baseCommitHash = git rev-parse HEAD~1
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash in pull request."
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
- name: CleanupCode (on branch)
if: github.event_name == 'push' || github.event_name == 'release'
shell: pwsh
run: |
Write-Output "Running code cleanup on all files."
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN --fail-on-diff --print-diff
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN --fail-on-diff --print-diff
publish:
timeout-minutes: 60
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
<RunSettingsFilePath>$(MSBuildThisFileDirectory)tests.runsettings</RunSettingsFilePath>
<JsonApiDotNetCoreMongoDbVersionPrefix>5.5.1</JsonApiDotNetCoreMongoDbVersionPrefix>
<JsonApiDotNetCoreMongoDbVersionPrefix>5.6.0</JsonApiDotNetCoreMongoDbVersionPrefix>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion JsonApiDotNetCore.MongoDb.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
.github\workflows\build.yml = .github\workflows\build.yml
CodingGuidelines.ruleset = CodingGuidelines.ruleset
CSharpGuidelinesAnalyzer.config = CSharpGuidelinesAnalyzer.config
Directory.Build.props = Directory.Build.props
tests.runsettings = tests.runsettings
package-versions.props = package-versions.props
tests.runsettings = tests.runsettings
EndProjectSection
EndProject
Global
Expand Down
4 changes: 3 additions & 1 deletion WarningSeverities.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToConstant_002ELocal/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToLambdaExpression/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToNullCoalescingCompoundAssignment/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToPrimaryConstructor/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToStaticClass/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToUsingDeclaration/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=DoubleNegationInPattern/@EntryIndexedValue">WARNING</s:String>
Expand Down Expand Up @@ -122,6 +123,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=NestedStringInterpolation/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=NotAccessedField_002EGlobal/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=OutdentIsOffPrevLevel/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PropertyCanBeMadeInitOnly_002EGlobal/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PropertyCanBeMadeInitOnly_002ELocal/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PublicConstructorInAbstractClass/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RawStringCanBeSimplified/@EntryIndexedValue">WARNING</s:String>
Expand Down Expand Up @@ -164,7 +166,6 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RemoveRedundantOrStatement_002ETrue/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RemoveToList_002E1/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RemoveToList_002E2/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceAsyncWithTaskReturn/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceObjectPatternWithVarPattern/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceSequenceEqualWithConstantPattern/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithFirstOrDefault_002E1/@EntryIndexedValue">WARNING</s:String>
Expand Down Expand Up @@ -196,6 +197,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithOfType_002ESingleOrDefault_002E1/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithOfType_002ESingleOrDefault_002E2/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithOfType_002EWhere/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithPrimaryConstructorParameter/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSimpleAssignment_002EFalse/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSimpleAssignment_002ETrue/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithSingleAssignment_002EFalse/@EntryIndexedValue">WARNING</s:String>
Expand Down
6 changes: 3 additions & 3 deletions cleanupcode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ if ($revision) {

if ($baseCommitHash -eq $headCommitHash) {
Write-Output "Running code cleanup on staged/unstaged files."
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f staged,modified
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f staged,modified
VerifySuccessExitCode
}
else {
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash, including staged/unstaged files."
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f staged,modified,commits -a $headCommitHash -b $baseCommitHash
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f staged,modified,commits -a $headCommitHash -b $baseCommitHash
VerifySuccessExitCode
}
}
else {
Write-Output "Running code cleanup on all files."
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN
VerifySuccessExitCode
}
Binary file removed logo.png
Binary file not shown.
Binary file added package-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions package-versions.props
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project>
<PropertyGroup>
<!-- Published dependencies (only update on major version change) -->
<JsonApiDotNetCoreFrozenVersion>5.5.0</JsonApiDotNetCoreFrozenVersion>
<JsonApiDotNetCoreFrozenVersion>5.6.0</JsonApiDotNetCoreFrozenVersion>
<MongoDBDriverFrozenVersion>2.20.0</MongoDBDriverFrozenVersion>

<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
<BogusVersion>34.0.*</BogusVersion>
<BogusVersion>35.5.*</BogusVersion>
<CoverletVersion>6.0.*</CoverletVersion>
<EphemeralMongoVersion>1.1.*</EphemeralMongoVersion>
<FluentAssertionsVersion>6.12.*</FluentAssertionsVersion>
<GitHubActionsTestLoggerVersion>2.3.*</GitHubActionsTestLoggerVersion>
<InheritDocVersion>1.3.*</InheritDocVersion>
<MongoDBDriverVersion>2.22.*</MongoDBDriverVersion>
<InheritDocVersion>2.0.*</InheritDocVersion>
<MongoDBDriverVersion>2.27.*</MongoDBDriverVersion>
<SourceLinkVersion>8.0.*</SourceLinkVersion>
<TestSdkVersion>17.8.*</TestSdkVersion>
<XunitVersion>2.5.*</XunitVersion>
<TestSdkVersion>17.10.*</TestSdkVersion>
<XunitVersion>2.8.*</XunitVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ namespace JsonApiDotNetCoreMongoDbExample.Controllers;

public sealed class OperationsController(
IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IOperationsProcessor processor, IJsonApiRequest request,
ITargetedFields targetedFields) : JsonApiOperationsController(options, resourceGraph, loggerFactory, processor, request, targetedFields);
ITargetedFields targetedFields, IAtomicOperationFilter operationFilter) : JsonApiOperationsController(options, resourceGraph, loggerFactory, processor,
request, targetedFields, operationFilter);
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,20 @@ public Task AfterProcessOperationAsync(CancellationToken cancellationToken)
}

/// <inheritdoc />
public Task CommitAsync(CancellationToken cancellationToken)
public async Task CommitAsync(CancellationToken cancellationToken)
{
if (_ownsTransaction && _mongoDataAccess.ActiveSession != null)
{
return _mongoDataAccess.ActiveSession.CommitTransactionAsync(cancellationToken);
await _mongoDataAccess.ActiveSession.CommitTransactionAsync(cancellationToken);
}

return Task.CompletedTask;
}

/// <inheritdoc />
public ValueTask DisposeAsync()
public async ValueTask DisposeAsync()
{
if (_ownsTransaction)
{
return _mongoDataAccess.DisposeAsync();
await _mongoDataAccess.DisposeAsync();
}

return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Reflection;
using JsonApiDotNetCore.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using MongoDB.Bson.Serialization.Attributes;

namespace JsonApiDotNetCore.MongoDb.Configuration;

internal static class ResourceGraphExtensions
{
public static IReadOnlyModel ToEntityModel(this IResourceGraph resourceGraph)
{
var modelBuilder = new ModelBuilder();

foreach (ResourceType resourceType in resourceGraph.GetResourceTypes())
{
IncludeResourceType(resourceType, modelBuilder);
}

return modelBuilder.Model;
}

private static void IncludeResourceType(ResourceType resourceType, ModelBuilder builder)
{
EntityTypeBuilder entityTypeBuilder = builder.Entity(resourceType.ClrType);

foreach (PropertyInfo property in resourceType.ClrType.GetProperties().Where(property => !IsIgnored(property)))
{
entityTypeBuilder.Property(property.PropertyType, property.Name);
}
}

private static bool IsIgnored(PropertyInfo property)
{
return property.GetCustomAttribute<BsonIgnoreAttribute>() != null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using JetBrains.Annotations;
using JsonApiDotNetCore.AtomicOperations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.MongoDb.AtomicOperations;
using JsonApiDotNetCore.MongoDb.Queries.Internal;
using JsonApiDotNetCore.MongoDb.Repositories;
Expand All @@ -17,6 +18,12 @@ public static class ServiceCollectionExtensions
[PublicAPI]
public static IServiceCollection AddJsonApiMongoDb(this IServiceCollection services)
{
services.TryAddSingleton(serviceProvider =>
{
var resourceGraph = serviceProvider.GetRequiredService<IResourceGraph>();
return resourceGraph.ToEntityModel();
});

services.TryAddScoped<IMongoDataAccess, MongoDataAccess>();

// Replace the built-in implementations from JsonApiDotNetCore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
<PackageTags>jsonapi;json:api;dotnet;asp.net;rest;web-api;MongoDB</PackageTags>
<Description>Persistence layer implementation for use of MongoDB in APIs using JsonApiDotNetCore.</Description>
<Authors>json-api-dotnet</Authors>
<PackageProjectUrl>https://github.com/json-api-dotnet/JsonApiDotNetCore.MongoDb</PackageProjectUrl>
<PackageProjectUrl>https://www.jsonapi.net/</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>See https://github.com/json-api-dotnet/JsonApiDotNetCore.MongoDb/releases.</PackageReleaseNotes>
<PackageIcon>logo.png</PackageIcon>
<PackageIcon>package-icon.png</PackageIcon>
<PackageReadmeFile>PackageReadme.md</PackageReadmeFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>embedded</DebugType>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\logo.png" Visible="false" Pack="True" PackagePath="" />
<None Include="..\..\package-icon.png" Visible="false" Pack="True" PackagePath="" />
<None Include="..\..\PackageReadme.md" Visible="false" Pack="True" PackagePath="" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.EntityFrameworkCore.Metadata;
using MongoDB.Driver;

namespace JsonApiDotNetCore.MongoDb.Repositories;
Expand All @@ -7,6 +8,11 @@ namespace JsonApiDotNetCore.MongoDb.Repositories;
/// </summary>
public interface IMongoDataAccess : IAsyncDisposable
{
/// <summary>
/// Provides access to the entity model, which is built at startup.
/// </summary>
IReadOnlyModel EntityModel { get; }

/// <summary>
/// Provides access to the underlying MongoDB database, which data changes can be applied on.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using Microsoft.EntityFrameworkCore.Metadata;
using MongoDB.Driver;

namespace JsonApiDotNetCore.MongoDb.Repositories;

/// <inheritdoc cref="IMongoDataAccess" />
public sealed class MongoDataAccess : IMongoDataAccess
{
/// <inheritdoc />
public IReadOnlyModel EntityModel { get; }

/// <inheritdoc />
public IMongoDatabase MongoDatabase { get; }

Expand All @@ -14,10 +18,12 @@ public sealed class MongoDataAccess : IMongoDataAccess
/// <inheritdoc />
public string? TransactionId => ActiveSession is { IsInTransaction: true } ? ActiveSession.GetHashCode().ToString() : null;

public MongoDataAccess(IMongoDatabase mongoDatabase)
public MongoDataAccess(IReadOnlyModel entityModel, IMongoDatabase mongoDatabase)
{
ArgumentGuard.NotNull(entityModel);
ArgumentGuard.NotNull(mongoDatabase);

EntityModel = entityModel;
MongoDatabase = mongoDatabase;
}

Expand Down
33 changes: 0 additions & 33 deletions src/JsonApiDotNetCore.MongoDb/Repositories/MongoModel.cs

This file was deleted.

Loading

0 comments on commit c26263c

Please sign in to comment.