-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial version of the library. (#1)
- Loading branch information
Showing
57 changed files
with
2,007 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31919.166 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".items", ".items", "{75AC41E9-2B8B-4D76-A7DF-A18F4FB9D6D6}" | ||
ProjectSection(SolutionItems) = preProject | ||
.gitignore = .gitignore | ||
azure-pipelines.yml = azure-pipelines.yml | ||
GitVersion.yml = GitVersion.yml | ||
icon.png = icon.png | ||
LICENSE = LICENSE | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DF28D730-99B3-4811-AAC7-725A73B3F668}" | ||
ProjectSection(SolutionItems) = preProject | ||
src\Directory.Build.props = src\Directory.Build.props | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F18D2D58-282C-4D93-8D9A-3A76CF98F018}" | ||
ProjectSection(SolutionItems) = preProject | ||
tests\Directory.Build.props = tests\Directory.Build.props | ||
EndProjectSection | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId", "src\Fluxera.StronglyTypedId\Fluxera.StronglyTypedId.csproj", "{0112DE42-7C32-4ECC-A5C1-6839C63A689C}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.UnitTests", "tests\Fluxera.StronglyTypedId.UnitTests\Fluxera.StronglyTypedId.UnitTests.csproj", "{6F6CAF72-1D71-434B-AD09-7A9216669502}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.JsonNet", "src\Fluxera.StronglyTypedId.JsonNet\Fluxera.StronglyTypedId.JsonNet.csproj", "{FA775AE5-1B74-4C42-94CF-03F3BD54E9F8}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.JsonNet.UnitTests", "tests\Fluxera.StronglyTypedId.JsonNet.UnitTests\Fluxera.StronglyTypedId.JsonNet.UnitTests.csproj", "{F92B3AEE-E3CF-49FF-857B-7205A7FD08EF}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.SystemTextJson", "src\Fluxera.StronglyTypedId.SystemTextJson\Fluxera.StronglyTypedId.SystemTextJson.csproj", "{78B29A90-2BD9-4603-B3E2-CBB71DD59BEE}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.SystemTextJson.UnitTests", "tests\Fluxera.StronglyTypedId.SystemTextJson.UnitTests\Fluxera.StronglyTypedId.SystemTextJson.UnitTests.csproj", "{4B5548EC-9CFF-4F83-9FDF-1831D439DB6B}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.LiteDB", "src\Fluxera.StronglyTypedId.LiteDB\Fluxera.StronglyTypedId.LiteDB.csproj", "{ACAAD773-D974-41DA-A04C-9A6B06766D82}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.LiteDB.UnitTests", "tests\Fluxera.StronglyTypedId.LiteDB.UnitTests\Fluxera.StronglyTypedId.LiteDB.UnitTests.csproj", "{5A4B736C-AEF7-4CF0-A27A-7E8ACD88B788}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.MongoDB", "src\Fluxera.StronglyTypedId.MongoDB\Fluxera.StronglyTypedId.MongoDB.csproj", "{8452ADA6-51E7-4E69-A83C-7EBC822E6AAB}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.MongoDB.UnitTests", "tests\Fluxera.StronglyTypedId.MongoDB.UnitTests\Fluxera.StronglyTypedId.MongoDB.UnitTests.csproj", "{75A3F24F-590F-457B-B031-B3A41FB51C02}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.EntityFrameworkCore", "src\Fluxera.StronglyTypedId.EntityFrameworkCore\Fluxera.StronglyTypedId.EntityFrameworkCore.csproj", "{AD7A0B26-A63A-47DC-897B-781206B084AC}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fluxera.StronglyTypedId.EntityFrameworkCore.UnitTests", "tests\Fluxera.StronglyTypedId.EntityFrameworkCore.UnitTests\Fluxera.StronglyTypedId.EntityFrameworkCore.UnitTests.csproj", "{1E08934F-F3FF-498A-B660-18E6C7C0958B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0112DE42-7C32-4ECC-A5C1-6839C63A689C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0112DE42-7C32-4ECC-A5C1-6839C63A689C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0112DE42-7C32-4ECC-A5C1-6839C63A689C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0112DE42-7C32-4ECC-A5C1-6839C63A689C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{6F6CAF72-1D71-434B-AD09-7A9216669502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6F6CAF72-1D71-434B-AD09-7A9216669502}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6F6CAF72-1D71-434B-AD09-7A9216669502}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6F6CAF72-1D71-434B-AD09-7A9216669502}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{FA775AE5-1B74-4C42-94CF-03F3BD54E9F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FA775AE5-1B74-4C42-94CF-03F3BD54E9F8}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FA775AE5-1B74-4C42-94CF-03F3BD54E9F8}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FA775AE5-1B74-4C42-94CF-03F3BD54E9F8}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{F92B3AEE-E3CF-49FF-857B-7205A7FD08EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F92B3AEE-E3CF-49FF-857B-7205A7FD08EF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F92B3AEE-E3CF-49FF-857B-7205A7FD08EF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F92B3AEE-E3CF-49FF-857B-7205A7FD08EF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{78B29A90-2BD9-4603-B3E2-CBB71DD59BEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{78B29A90-2BD9-4603-B3E2-CBB71DD59BEE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{78B29A90-2BD9-4603-B3E2-CBB71DD59BEE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{78B29A90-2BD9-4603-B3E2-CBB71DD59BEE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{4B5548EC-9CFF-4F83-9FDF-1831D439DB6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4B5548EC-9CFF-4F83-9FDF-1831D439DB6B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4B5548EC-9CFF-4F83-9FDF-1831D439DB6B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4B5548EC-9CFF-4F83-9FDF-1831D439DB6B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{ACAAD773-D974-41DA-A04C-9A6B06766D82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{ACAAD773-D974-41DA-A04C-9A6B06766D82}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{ACAAD773-D974-41DA-A04C-9A6B06766D82}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{ACAAD773-D974-41DA-A04C-9A6B06766D82}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{5A4B736C-AEF7-4CF0-A27A-7E8ACD88B788}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5A4B736C-AEF7-4CF0-A27A-7E8ACD88B788}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5A4B736C-AEF7-4CF0-A27A-7E8ACD88B788}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5A4B736C-AEF7-4CF0-A27A-7E8ACD88B788}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{8452ADA6-51E7-4E69-A83C-7EBC822E6AAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8452ADA6-51E7-4E69-A83C-7EBC822E6AAB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8452ADA6-51E7-4E69-A83C-7EBC822E6AAB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8452ADA6-51E7-4E69-A83C-7EBC822E6AAB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{75A3F24F-590F-457B-B031-B3A41FB51C02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{75A3F24F-590F-457B-B031-B3A41FB51C02}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{75A3F24F-590F-457B-B031-B3A41FB51C02}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{75A3F24F-590F-457B-B031-B3A41FB51C02}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{AD7A0B26-A63A-47DC-897B-781206B084AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AD7A0B26-A63A-47DC-897B-781206B084AC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AD7A0B26-A63A-47DC-897B-781206B084AC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AD7A0B26-A63A-47DC-897B-781206B084AC}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1E08934F-F3FF-498A-B660-18E6C7C0958B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1E08934F-F3FF-498A-B660-18E6C7C0958B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1E08934F-F3FF-498A-B660-18E6C7C0958B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1E08934F-F3FF-498A-B660-18E6C7C0958B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{0112DE42-7C32-4ECC-A5C1-6839C63A689C} = {DF28D730-99B3-4811-AAC7-725A73B3F668} | ||
{6F6CAF72-1D71-434B-AD09-7A9216669502} = {F18D2D58-282C-4D93-8D9A-3A76CF98F018} | ||
{FA775AE5-1B74-4C42-94CF-03F3BD54E9F8} = {DF28D730-99B3-4811-AAC7-725A73B3F668} | ||
{F92B3AEE-E3CF-49FF-857B-7205A7FD08EF} = {F18D2D58-282C-4D93-8D9A-3A76CF98F018} | ||
{78B29A90-2BD9-4603-B3E2-CBB71DD59BEE} = {DF28D730-99B3-4811-AAC7-725A73B3F668} | ||
{4B5548EC-9CFF-4F83-9FDF-1831D439DB6B} = {F18D2D58-282C-4D93-8D9A-3A76CF98F018} | ||
{ACAAD773-D974-41DA-A04C-9A6B06766D82} = {DF28D730-99B3-4811-AAC7-725A73B3F668} | ||
{5A4B736C-AEF7-4CF0-A27A-7E8ACD88B788} = {F18D2D58-282C-4D93-8D9A-3A76CF98F018} | ||
{8452ADA6-51E7-4E69-A83C-7EBC822E6AAB} = {DF28D730-99B3-4811-AAC7-725A73B3F668} | ||
{75A3F24F-590F-457B-B031-B3A41FB51C02} = {F18D2D58-282C-4D93-8D9A-3A76CF98F018} | ||
{AD7A0B26-A63A-47DC-897B-781206B084AC} = {DF28D730-99B3-4811-AAC7-725A73B3F668} | ||
{1E08934F-F3FF-498A-B660-18E6C7C0958B} = {F18D2D58-282C-4D93-8D9A-3A76CF98F018} | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {D97BF2AF-6E68-4E88-BF70-773A86E26013} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mode: Mainline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# Fluxera.StronglyTypedId | ||
|
||
A library that provides strongly-typed Ids without code generation. | ||
|
||
|
||
## Usage | ||
|
||
To implement a strongly-typed ID just inherit from the ```StronglyTypedId<,>``` base class. | ||
The base class implements all aspects of the ID, like quality and comparablility. | ||
|
||
```C# | ||
public sealed class PersonId : StronglyTypedId<PersonId, string> | ||
{ | ||
/// <inheritdoc /> | ||
public PersonId(string value) : base(value) | ||
{ | ||
} | ||
} | ||
``` | ||
|
||
## Serializer Support | ||
|
||
This library provides serializer support for the following libaries: | ||
|
||
- EF Core | ||
- JSON.NET | ||
- LiteDB | ||
- MongoDB | ||
- System.Text.Json | ||
|
||
To use the serializer support just use the ```UseStronglyTypedId``` extension method to configure the | ||
corresponding serializer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# CI pipeline for a NuGet package solution. | ||
|
||
trigger: | ||
branches: | ||
include: [ '*' ] | ||
exclude: [ 'refs/tags/*' ] | ||
|
||
variables: | ||
BuildConfiguration: Release | ||
DotNetCoreVersion: 6.0.x | ||
|
||
stages: | ||
- stage: BuildAndTest | ||
jobs: | ||
- job: BuildAndTest | ||
pool: | ||
name: Default | ||
steps: | ||
- checkout: self | ||
persistCredentials: 'true' | ||
clean: true | ||
# Install the desired .NET SDK. | ||
- task: UseDotNet@2 | ||
displayName: 'Acquire .NET SDK' | ||
inputs: | ||
packageType: 'sdk' | ||
version: $(DotNetCoreVersion) | ||
includePreviewVersions: false | ||
# Build all projects. | ||
- task: DotNetCoreCLI@2 | ||
displayName: 'Build Projects' | ||
inputs: | ||
projects: '**/*.csproj' | ||
arguments: '--configuration $(BuildConfiguration)' | ||
# Run all available tests. | ||
- task: DotNetCoreCLI@2 | ||
displayName: 'Execute Tests' | ||
inputs: | ||
command: test | ||
projects: '**/*Tests/*.csproj' | ||
arguments: '--configuration $(BuildConfiguration)' | ||
nobuild: true | ||
# Create the NuGet packages. | ||
- task: DotNetCoreCLI@2 | ||
displayName: 'Pack Packages' | ||
inputs: | ||
command: 'pack' | ||
packagesToPack: 'src/**/*.csproj' | ||
nobuild: true | ||
verbosityPack: Minimal | ||
includesymbols: false | ||
# Copy created NuGet packages to the builds artifacts directory. | ||
- task: PublishBuildArtifacts@1 | ||
displayName: 'Publish Package Artifacts' | ||
inputs: | ||
PathtoPublish: '$(Build.ArtifactStagingDirectory)' | ||
ArtifactName: 'packages' | ||
publishLocation: 'Container' | ||
|
||
- stage: PublishPackages | ||
dependsOn: BuildAndTest | ||
# Only publish packages for main branch. | ||
condition: and(succeeded('BuildAndTest'), eq(variables['Build.SourceBranch'], 'refs/heads/main')) | ||
jobs: | ||
- job: PublishPackages | ||
pool: | ||
name: Default | ||
steps: | ||
# Download the created packages. | ||
- task: DownloadBuildArtifacts@0 | ||
displayName: 'Download NuGet Packges' | ||
inputs: | ||
buildType: 'current' | ||
downloadType: 'single' | ||
artifactName: 'packages' | ||
downloadPath: '$(System.ArtifactsDirectory)' | ||
# Publish the NuGet packages to the package feed. | ||
- task: DotNetCoreCLI@2 | ||
displayName: Push Nuget Package | ||
inputs: | ||
command: custom | ||
custom: nuget | ||
arguments: > | ||
push $(System.ArtifactsDirectory)/**/*.nupkg | ||
-s https://api.nuget.org/v3/index.json | ||
-k $(NuGetApiKey) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<LangVersion>latest</LangVersion> | ||
<Nullable>disable</Nullable> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Company>Fluxera Software Development GmbH</Company> | ||
<Product>Fluxera Software Foundation</Product> | ||
<Copyright>Copyright © 2014-2022 Fluxera Software Development GmbH. All rights reserved.</Copyright> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Authors>Matthias Gernand</Authors> | ||
<RepositoryUrl>https://github.com/fluxera/Fluxera.Guard</RepositoryUrl> | ||
<PackageProjectUrl>https://github.com/fluxera/Fluxera.Guard</PackageProjectUrl> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<IncludeSymbols>false</IncludeSymbols> | ||
<NeutralLanguage>en</NeutralLanguage> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
</PropertyGroup> | ||
|
||
<Target Name="Update Version" BeforeTargets="Build" Condition="'$(TF_BUILD)' == 'true'"> | ||
<Message Text="Version = $(GITVERSION_FullSemVer)" Importance="High" /> | ||
<Message Text="##vso[build.updatebuildnumber]$(GITVERSION_FullSemVer)" Importance="High" /> | ||
</Target> | ||
|
||
</Project> |
37 changes: 37 additions & 0 deletions
37
...ra.StronglyTypedId.EntityFrameworkCore/Fluxera.StronglyTypedId.EntityFrameworkCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Title>Fluxera.StronglyTypedId.EntityFrameworkCore</Title> | ||
<Description>A libary that provides serializer support for EF Core for strongly-typed IDs.</Description> | ||
<PackageTags>fluxera;library;ddd;value-object;ef-core</PackageTags> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md" Link="Properties\README.md"> | ||
<Pack>true</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
<None Include="..\..\icon.png" Link="Properties\icon.png"> | ||
<Pack>true</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="GitVersion.MsBuild" Version="5.10.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.5" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Fluxera.StronglyTypedId\Fluxera.StronglyTypedId.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
53 changes: 53 additions & 0 deletions
53
src/Fluxera.StronglyTypedId.EntityFrameworkCore/ModelBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace Fluxera.StronglyTypedId.EntityFrameworkCore | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Fluxera.Guards; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
|
||
/// <summary> | ||
/// Extension methods for the <see cref="ModelBuilder" /> type. | ||
/// </summary> | ||
[PublicAPI] | ||
public static class ModelBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Configure the module builder to use the <see cref="StronglyTypedIdConverter{TStronglyTypedId,TValue}" />. | ||
/// </summary> | ||
/// <param name="modelBuilder"></param> | ||
public static void UseStronglyTypedId(this ModelBuilder modelBuilder) | ||
{ | ||
Guard.Against.Null(modelBuilder, nameof(modelBuilder)); | ||
|
||
foreach(IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes()) | ||
{ | ||
IEnumerable<PropertyInfo> properties = entityType | ||
.ClrType | ||
.GetProperties() | ||
.Where(type => type.PropertyType.IsStronglyTypedId()); | ||
|
||
foreach(PropertyInfo property in properties) | ||
{ | ||
Type enumerationType = property.PropertyType; | ||
Type valueType = enumerationType.GetValueType(); | ||
|
||
Type converterTypeTemplate = typeof(StronglyTypedIdConverter<,>); | ||
|
||
Type converterType = converterTypeTemplate.MakeGenericType(enumerationType, valueType); | ||
|
||
ValueConverter converter = (ValueConverter)Activator.CreateInstance(converterType); | ||
|
||
modelBuilder | ||
.Entity(entityType.ClrType) | ||
.Property(property.Name) | ||
.HasConversion(converter); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.