Skip to content

Commit

Permalink
merging 0.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Jul 20, 2020
2 parents 181a0f3 + ff295b5 commit d77797d
Show file tree
Hide file tree
Showing 81 changed files with 1,675 additions and 429 deletions.
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

# C# files
[*.cs]

#### Suppress warnings ####

# CA1034: Nested types should not be visible
dotnet_diagnostic.CA1034.severity = none

# CA1063: Implement IDisposable Correctly
dotnet_diagnostic.CA1063.severity = none

# CA1303: Do not pass literals as localized parameters
dotnet_diagnostic.CA1303.severity = none # Don't need translated exceptions

# CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1707.severity = none # I want to use underscore in constants

# CA1812: Avoid uninstantiated internal classes
dotnet_diagnostic.CA1812.severity = none # Doing extensive use of dependency injection

# CA1816: Dispose methods should call SuppressFinalize
dotnet_diagnostic.CA1816.severity = none

# CA2225: Operator overloads have named alternates
dotnet_diagnostic.CA2225.severity = none
29 changes: 0 additions & 29 deletions .github/workflows/myget-feature-deploy.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Build test and package dev and master branch. Deploy to MyGet
name: Unstable release deploy to MyGet

on:
push:
branches: [ master, dev ]
branches:
- dev
- 'release/**'

jobs:
build-test-package:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Build test and package master branch. Deploy to NuGet
name: Stable release deploy to NuGet

on:
push:
branches: master
branches:
- master

jobs:
build-test-package:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ publish/

# NuGet Packages
*.nupkg
*.snupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
Expand Down
7 changes: 4 additions & 3 deletions MongODM.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongODM.Core.Tests", "test\
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{03C64D98-FF9F-4760-AE82-203953FF4940}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
LICENSE.txt = LICENSE.txt
MongODM.sln.licenseheader = MongODM.sln.licenseheader
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{D4BB5972-5F7B-43ED-81C1-69ECF0E62D1E}"
ProjectSection(SolutionItems) = preProject
.github\workflows\myget-feature-deploy.yml = .github\workflows\myget-feature-deploy.yml
.github\workflows\myget-stable-deploy.yml = .github\workflows\myget-stable-deploy.yml
.github\workflows\nuget-release-deploy.yml = .github\workflows\nuget-release-deploy.yml
.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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MongODM
MongODM
=========

## Overview
Expand Down
9 changes: 9 additions & 0 deletions src/ExecutionContext/ExecutionContext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<Description>Execution context provider</Description>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>

<RepositoryUrl>https://github.com/Etherna/mongodm</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
</PropertyGroup>

Expand All @@ -21,6 +26,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/MongODM.AspNetCore/MongODM.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<Description>Asp.Net Core adapter for MongODM</Description>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>

<RepositoryUrl>https://github.com/Etherna/mongodm</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
</PropertyGroup>

Expand All @@ -31,6 +36,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 17 additions & 7 deletions src/MongODM.AspNetCore/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Etherna.ExecContext.AsyncLocal;
using Etherna.MongODM;
using Etherna.MongODM.AspNetCore;
using Etherna.MongODM.Models;
using Etherna.MongODM.ProxyModels;
using Etherna.MongODM.Repositories;
using Etherna.MongODM.Serialization;
Expand All @@ -32,17 +33,21 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static MongODMConfiguration UseMongODM<TTaskRunner>(
public static MongODMConfiguration UseMongODM<TTaskRunner, TModelBase>(
this IServiceCollection services,
IEnumerable<IExecutionContext>? executionContexts = null)
where TTaskRunner : class, ITaskRunner =>
UseMongODM<ProxyGenerator, TTaskRunner>(services, executionContexts);
where TTaskRunner : class, ITaskRunner
where TModelBase : class, IModel => //needed because of this https://jira.mongodb.org/browse/CSHARP-3154
UseMongODM<ProxyGenerator, TTaskRunner, TModelBase>(
services,
executionContexts);

public static MongODMConfiguration UseMongODM<TProxyGenerator, TTaskRunner>(
public static MongODMConfiguration UseMongODM<TProxyGenerator, TTaskRunner, TModelBase>(
this IServiceCollection services,
IEnumerable<IExecutionContext>? executionContexts = null)
where TProxyGenerator: class, IProxyGenerator
where TProxyGenerator : class, IProxyGenerator
where TTaskRunner: class, ITaskRunner
where TModelBase: class, IModel //needed because of this https://jira.mongodb.org/browse/CSHARP-3154
{
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

Expand Down Expand Up @@ -70,18 +75,23 @@ public static MongODMConfiguration UseMongODM<TProxyGenerator, TTaskRunner>(
* the same dbContext different components could have different instances of the same component.
*/
services.TryAddTransient<IDbCache, DbCache>();
services.TryAddTransient<IDbContextDependencies, DbContextDependencies>();
services.TryAddTransient<IDbDependencies, DbDependencies>();
services.TryAddTransient<IDbMaintainer, DbMaintainer>();
services.TryAddTransient<IDbMigrationManager, DbMigrationManager>();
services.TryAddTransient<IDocumentSchemaRegister, DocumentSchemaRegister>();
services.TryAddTransient<IRepositoryRegister, RepositoryRegister>();
services.TryAddSingleton<ISerializerModifierAccessor, SerializerModifierAccessor>();

//tasks
services.TryAddTransient<IMigrateDbContextTask, MigrateDbContextTask>();
services.TryAddTransient<IUpdateDocDependenciesTask, UpdateDocDependenciesTask>();

//castle proxy generator.
//castle proxy generator
services.TryAddSingleton<Castle.DynamicProxy.IProxyGenerator>(new Castle.DynamicProxy.ProxyGenerator());

//static configurations
services.TryAddSingleton<IStaticConfigurationBuilder, StaticConfigurationBuilder<TModelBase>>();

return new MongODMConfiguration(services);
}

Expand Down
41 changes: 41 additions & 0 deletions src/MongODM.AspNetCore/StaticConfigurationBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020-present Etherna Sagl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.

using Etherna.MongODM.Conventions;
using Etherna.MongODM.Models.Internal;
using Etherna.MongODM.ProxyModels;
using Etherna.MongODM.Utility;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;

namespace Etherna.MongODM.AspNetCore
{
public class StaticConfigurationBuilder<TModelBase> : IStaticConfigurationBuilder
{
public StaticConfigurationBuilder(IProxyGenerator proxyGenerator)
{
// Register conventions.
ConventionRegistry.Register("Enum string", new ConventionPack
{
new EnumRepresentationConvention(BsonType.String)
}, c => true);

BsonSerializer.RegisterDiscriminatorConvention(typeof(TModelBase),
new HierarchicalProxyTolerantDiscriminatorConvention("_t", proxyGenerator));
BsonSerializer.RegisterDiscriminatorConvention(typeof(EntityModelBase),
new HierarchicalProxyTolerantDiscriminatorConvention("_t", proxyGenerator));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2020-present Etherna Sagl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.

using Etherna.MongODM.ProxyModels;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Conventions;
using System;

namespace Etherna.MongODM.Conventions
{
public class HierarchicalProxyTolerantDiscriminatorConvention : HierarchicalDiscriminatorConvention
{
// Fields.
private readonly IProxyGenerator proxyGenerator;

// Constructors.
public HierarchicalProxyTolerantDiscriminatorConvention(
string elementName,
IProxyGenerator proxyGenerator)
: base(elementName)
{
this.proxyGenerator = proxyGenerator ?? throw new ArgumentNullException(nameof(proxyGenerator));
}

// Methods.
public override BsonValue GetDiscriminator(Type nominalType, Type actualType) =>
base.GetDiscriminator(nominalType, proxyGenerator.PurgeProxyType(actualType));
}
}
Loading

0 comments on commit d77797d

Please sign in to comment.