Skip to content

Commit

Permalink
Merge pull request #71 from Etherna/improve/MODM-168-support-dotnet8
Browse files Browse the repository at this point in the history
support dotnet 8
  • Loading branch information
tmm360 authored Mar 21, 2024
2 parents a15f4e7 + 0a582f2 commit 583f542
Show file tree
Hide file tree
Showing 66 changed files with 358 additions and 368 deletions.
41 changes: 22 additions & 19 deletions .github/workflows/myget-unstable-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,36 @@ name: Unstable release deploy to MyGet
on:
push:
branches:
- dev
- 'release/**'
- dev
- 'hotfix/**'
- 'release/**'

jobs:
build-test-package:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Build with dotnet
run: dotnet build --configuration Release
- name: Build with dotnet
run: dotnet build --configuration Release

- name: Run unit tests
run: dotnet test --configuration Release
- name: Run unit tests
run: dotnet test --configuration Release

- name: Generate nuget package
run: dotnet pack --configuration Release -o nupkg
- name: Generate nuget package
run: dotnet pack --configuration Release -o nupkg

- name: Push packages
run: dotnet nuget push './nupkg/*.nupkg' --api-key ${{secrets.MYGET_APIKEY}} --source https://www.myget.org/F/etherna/api/v3/index.json
- name: Push packages
run: dotnet nuget push './nupkg/*.nupkg' --api-key ${{secrets.MYGET_APIKEY}} --source https://www.myget.org/F/etherna/api/v3/index.json
46 changes: 24 additions & 22 deletions .github/workflows/nuget-stable-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
- name: Build with dotnet
run: dotnet build --configuration Release

- name: Run unit tests
run: dotnet test --configuration Release

- name: Generate nuget package
run: dotnet pack --configuration Release -o nupkg

- name: Push packages
run: dotnet nuget push './nupkg/*.nupkg' --api-key ${{secrets.NUGET_KEY}} --source https://api.nuget.org/v3/index.json
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Build with dotnet
run: dotnet build --configuration Release

- name: Run unit tests
run: dotnet test --configuration Release

- name: Generate nuget package
run: dotnet pack --configuration Release -o nupkg

- name: Push packages
run: dotnet nuget push './nupkg/*.nupkg' --api-key ${{secrets.NUGET_KEY}} --source https://api.nuget.org/v3/index.json
7 changes: 7 additions & 0 deletions MongODM.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongODM.AspNetCore.UI", "sr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCoreSample", "samples\AspNetCoreSample\AspNetCoreSample.csproj", "{E4DE982C-B684-40B0-A647-565363332BF3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{5F6B8B10-C8E6-458C-9CF7-52ACDECF662D}"
ProjectSection(SolutionItems) = preProject
.github\workflows\myget-unstable-deploy.yml = .github\workflows\myget-unstable-deploy.yml
.github\workflows\nuget-stable-deploy.yml = .github\workflows\nuget-stable-deploy.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -77,6 +83,7 @@ Global
{0C53354C-B5F3-438A-A5EA-26C6F7E92E38} = {490DAED7-DAD8-459A-A20E-F57F2F6F619E}
{A1821261-1FEE-430E-84CC-8D88867D4011} = {490DAED7-DAD8-459A-A20E-F57F2F6F619E}
{E4DE982C-B684-40B0-A647-565363332BF3} = {00FD3F85-6217-4947-9D26-7B2E9A8920CF}
{5F6B8B10-C8E6-458C-9CF7-52ACDECF662D} = {03C64D98-FF9F-4760-AE82-203953FF4940}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {43A8089E-9445-4DE1-B509-F049E211B555}
Expand Down
4 changes: 3 additions & 1 deletion MongODM.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.</s:String></wpf:ResourceDictionary>
limitations under the License.</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Etherna/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MongODM/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion samples/AspNetCoreSample/AspNetCoreSample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Etherna.MongODM.AspNetCoreSample</RootNamespace>

<Authors>Etherna SA</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public IndexModel(
IOptions<MongODMOptions> options,
IServiceProvider serviceProvider)
{
if (options is null)
throw new ArgumentNullException(nameof(options));
ArgumentNullException.ThrowIfNull(options, nameof(options));

this.options = options.Value;
this.serviceProvider = serviceProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.AspNetCore.UI/MongODM.AspNetCore.UI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<RootNamespace>Etherna.MongODM.AspNetCore.UI</RootNamespace>
Expand Down
3 changes: 1 addition & 2 deletions src/MongODM.AspNetCore.UI/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public static IServiceCollection AddMongODMAdminDashboard(
this IServiceCollection services,
DashboardOptions? dashboardOptions = null)
{
if (services is null)
throw new ArgumentNullException(nameof(services));
ArgumentNullException.ThrowIfNull(services, nameof(services));

dashboardOptions ??= new DashboardOptions();

Expand Down
3 changes: 1 addition & 2 deletions src/MongODM.AspNetCore/DbDependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public DbDependencies(
IRepositoryRegistry repositoryRegistry,
ISerializerModifierAccessor serializerModifierAccessor)
{
if (mongODMOptions is null)
throw new ArgumentNullException(nameof(mongODMOptions));
ArgumentNullException.ThrowIfNull(mongODMOptions, nameof(mongODMOptions));
BsonSerializerRegistry = bsonSerializerRegistry;
DbCache = dbCache;
DbMaintainer = dbMaintainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static class ApplicationBuilderExtensions
public static IApplicationBuilder SeedDbContexts(
this IApplicationBuilder builder)
{
if (builder is null)
throw new ArgumentNullException(nameof(builder));
ArgumentNullException.ThrowIfNull(builder, nameof(builder));

var serviceProvider = builder.ApplicationServices;
var mongODMOptions = serviceProvider.GetRequiredService<IOptions<MongODMOptions>>();
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.AspNetCore/MongODM.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<RootNamespace>Etherna.MongODM.AspNetCore</RootNamespace>
<Authors>Etherna SA</Authors>
Expand Down
3 changes: 1 addition & 2 deletions src/MongODM.AspNetCore/MongODMConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ public IMongODMConfiguration AddDbContext<TDbContext, TDbContextImpl>(

public void Freeze(IMongODMOptionsBuilder mongODMOptionsBuilder)
{
if (mongODMOptionsBuilder is null)
throw new ArgumentNullException(nameof(mongODMOptionsBuilder));
ArgumentNullException.ThrowIfNull(mongODMOptionsBuilder, nameof(mongODMOptionsBuilder));

configLock.EnterReadLock();
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Etherna.MongODM.Core.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Etherna.MongODM.Core.Conventions
Expand All @@ -32,6 +33,8 @@ public class HierarchicalProxyTolerantDiscriminatorConvention : IDiscriminatorCo
private readonly IExecutionContext? executionContext;

// Constructors.
[SuppressMessage("Usage", "CA2249:Consider using \'string.Contains\' instead of \'string.IndexOf\'")]
[SuppressMessage("Globalization", "CA1307:Specify StringComparison for clarity")]
public HierarchicalProxyTolerantDiscriminatorConvention(
IDbContext dbContext,
string elementName)
Expand All @@ -49,6 +52,8 @@ public HierarchicalProxyTolerantDiscriminatorConvention(
/// </summary>
/// <param name="elementName">Discriminator element name</param>
/// <param name="executionContext">Execution context</param>
[SuppressMessage("Usage", "CA2249:Consider using \'string.Contains\' instead of \'string.IndexOf\'")]
[SuppressMessage("Globalization", "CA1307:Specify StringComparison for clarity")]
public HierarchicalProxyTolerantDiscriminatorConvention(
string elementName,
IExecutionContext executionContext)
Expand Down Expand Up @@ -81,8 +86,7 @@ public IDbContext DbContext
// Methods.
public Type GetActualType(IBsonReader bsonReader, Type nominalType)
{
if (bsonReader is null)
throw new ArgumentNullException(nameof(bsonReader));
ArgumentNullException.ThrowIfNull(bsonReader, nameof(bsonReader));

//the BsonReader is sitting at the value whose actual type needs to be found
var bsonType = bsonReader.GetCurrentBsonType();
Expand Down
30 changes: 25 additions & 5 deletions src/MongODM.Core/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@

namespace Etherna.MongODM.Core
{
public abstract class DbContext : IDbContext, IDbContextBuilder
public abstract class DbContext : IDbContext, IDbContextBuilder, IDisposable
{
// Fields.
private bool? _isSeeded;
private BsonSerializerRegistry _serializerRegistry = default!;
private IEnumerable<IDbContext> childDbContexts = default!;
private bool disposed;
private bool isInitialized;
private readonly ReaderWriterLockSlim isSeededLock = new(); //support read/write locks
private readonly ILogger logger;
Expand All @@ -64,10 +65,8 @@ public void Initialize(
{
if (isInitialized)
throw new InvalidOperationException("DbContext already initialized");
if (dependencies is null)
throw new ArgumentNullException(nameof(dependencies));
if (options is null)
throw new ArgumentNullException(nameof(options));
ArgumentNullException.ThrowIfNull(dependencies, nameof(dependencies));
ArgumentNullException.ThrowIfNull(options, nameof(options));

// Set dependencies.
this.childDbContexts = childDbContexts;
Expand Down Expand Up @@ -126,6 +125,27 @@ public void Initialize(

logger.DbContextInitialized(options.DbName);
}

// Dispose.
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposed) return;

// Dispose managed resources.
if (disposing)
{
isSeededLock.Dispose();
seedingSemaphore.Dispose();
}

disposed = true;
}

// Public properties.
public IReadOnlyCollection<IEntityModel> ChangedModelsList =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Etherna.MongODM.Core.Domain.ModelMaps
{
class DbMigrationOperationMap : IModelMapsCollector
internal sealed class DbMigrationOperationMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/Domain/ModelMaps/ModelBaseMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Etherna.MongODM.Core.Domain.ModelMaps
{
class ModelBaseMap : IModelMapsCollector
internal sealed class ModelBaseMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/Domain/ModelMaps/OperationBaseMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Etherna.MongODM.Core.Domain.ModelMaps
{
class OperationBaseMap : IModelMapsCollector
internal sealed class OperationBaseMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/Domain/ModelMaps/SeedOperationMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Etherna.MongODM.Core.Domain.ModelMaps
{
class SeedOperationMap : IModelMapsCollector
internal sealed class SeedOperationMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
Expand Down
6 changes: 2 additions & 4 deletions src/MongODM.Core/Domain/Models/DbMigrationOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public virtual IEnumerable<MigrationLogBase> Logs
[PropertyAlterer(nameof(Logs))]
public virtual void AddLog(MigrationLogBase log)
{
if (log is null)
throw new ArgumentNullException(nameof(log));
ArgumentNullException.ThrowIfNull(log, nameof(log));

_logs.Add(log);
}
Expand Down Expand Up @@ -97,8 +96,7 @@ public virtual void TaskFailed()
[PropertyAlterer(nameof(TaskId))]
public virtual void TaskStarted(string taskId)
{
if (taskId is null)
throw new ArgumentNullException(nameof(taskId));
ArgumentNullException.ThrowIfNull(taskId, nameof(taskId));

if (CurrentStatus != Status.New)
throw new InvalidOperationException();
Expand Down
3 changes: 1 addition & 2 deletions src/MongODM.Core/Domain/Models/OperationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public abstract class OperationBase : EntityModelBase<string>
// Constructors and dispose.
protected OperationBase(IDbContext dbContext)
{
if (dbContext is null)
throw new ArgumentNullException(nameof(dbContext));
ArgumentNullException.ThrowIfNull(dbContext, nameof(dbContext));

CreationDateTime = DateTime.Now;
DbContextName = dbContext.Identifier;
Expand Down
Loading

0 comments on commit 583f542

Please sign in to comment.