Skip to content

Commit

Permalink
.NET 8 and EF Core 8 (#3)
Browse files Browse the repository at this point in the history
* Upgrade to .NET 8 and remove legacy full framework projects
* Test refactoring
* Cleanup
* Dispose DB context on repository disposal
* Bump and publish 2.0.0.0
  • Loading branch information
hbulens authored Dec 7, 2023
1 parent 28fecf9 commit c48e07b
Show file tree
Hide file tree
Showing 124 changed files with 791 additions and 5,307 deletions.
76 changes: 21 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
<p align="center"><img src="assets/db.svg?raw=true" width="350" alt="Logo"></p>
<p align="center"><img src="assets/logo.png" width="350" alt="Logo"></p>

# Repositories
<div align="center">
<h1>Repositories</h1>
</div>

[![Build Status](https://dev.azure.com/dimesoftware/Utilities/_apis/build/status/dimesoftware.repository?branchName=master)](https://dev.azure.com/dimesoftware/Utilities/_build/latest?definitionId=182&branchName=master)
Implementation of the repository pattern with Entity Framework.

## Introduction

Implementation of the repository pattern with Entity Framework (Core).

## Getting Started

- You must have Visual Studio 2019 Community or higher.
- The dotnet cli is also highly recommended.

## About this project

Generic repository pattern with an implementation using Entity Framework. This project revolves around the `IRepository<T>` interface. This interfaces defines the capabilities of a repository which - rather unsurprisingly - are simple CRUD operations.

In addition, this project is also concerned with instantiating the repositories. Rather than accessing the repository's implementation directly, a repository factory (defined by `IRepositoryFactory`) can be used and injected into the application. Support for multi-tenancy is built-in with the `IMultiTenantRepositoryFactory` interface.
In addition, this project is also concerned with instantiating the repositories. Rather than accessing the repository's implementation directly, a repository factory (defined by `IRepositoryFactory`) can be used and injected into the application.

The projects in the `Providers` folder provide the implementation of the contracts defined in the Dime.Repositories assembly.

## Build and Test

- Run dotnet restore
- Run dotnet build
- Run dotnet test

## Installation
## Getting started

Use the package manager NuGet to install Dime.Repositories:

Expand All @@ -39,55 +27,33 @@ Here's a simple example which demonstrates the usage of the repository.

``` csharp
using Dime.Repositories;
...

public class CustomerService
{
private readonly IRepositoryFactory _repositoryFactory;

public CustomerService(IRepositoryFactory repositoryFactory)
private readonly IRepository<Customer> _repository;
public CustomerService(IRepository<Customer> repository)
{
_repositoryFactory = repositoryFactory;
_repository = repository;
}

public async IEnumerable<Customer> GetCustomers()
{
using IRepository<Customer> customerRepository = _repositoryFactory.Create<Customer>();
return await customerRepository.FindAllAsync(x => x.IsActive == true);
}
=> await _repository_.FindAllAsync(x => x.IsActive == true);
}
```

This is an example of the dependency injection registration in Unity:
## Build and Test

```csharp
public sealed class UnityConfig
{
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterType<IMultiTenantEfRepositoryFactory, EfRepositoryFactory<MyDbContext>>(
new PerRequestOrTransientLifeTimeManager(),
new InjectionConstructor(new MyDbContextEfContextFactory()));
}
}
To run the solution, you will need:

public class MyDbContextEfContextFactory : MultiTenantContextFactory<MyDbContext>
{
...

protected override SchedulerContext ConstructContext()
{
MyDbContext ctx = new MyDbContext();
ctx.Configuration.ProxyCreationEnabled = false;
ctx.Configuration.LazyLoadingEnabled = false;
ctx.Configuration.AutoDetectChangesEnabled = false;
ctx.Configuration.UseDatabaseNullSemantics = true;
ctx.Database.CommandTimeout = 60;
return ctx;
}
}
```
- You must have Visual Studio 2022 Community or higher.
- The dotnet cli is also highly recommended.

To run the tests, you can use the trustee dotnet cli commands:

- Run dotnet restore
- Run dotnet build
- Run dotnet test

## Contributing

![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)
Expand Down
1 change: 0 additions & 1 deletion assets/db.svg

This file was deleted.

Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 0 additions & 28 deletions azure-pipelines.yaml

This file was deleted.

29 changes: 4 additions & 25 deletions src/Dime.Repositories.sln
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dime.Repositories", "core\Dime.Repositories\Dime.Repositories.csproj", "{72A74CEB-EC06-43A8-85C2-E4CFDA8DFCE9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F753A01F-2E0C-4036-9DEF-6047253255D2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dime.Repositories.Sql", "core\Dime.Repositories.Sql\Dime.Repositories.Sql.csproj", "{0FB51C4F-7198-40CF-8442-9A09BF016C42}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dime.Repositories.Sql.EntityFramework.NetCore", "providers\EntityFramework.NetCore\Dime.Repositories.Sql.EntityFramework.NetCore.csproj", "{B501E673-CC10-4BFF-A086-CFF1DF482816}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dime.Repositories.Sql.EntityFramework", "providers\EntityFramework\Dime.Repositories.Sql.EntityFramework.csproj", "{B501E673-CC10-4BFF-A086-CFF1DF482816}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dime.Repositories.Sql.EntityFramework.NetFramework", "providers\EntityFramework.NetFramework\Dime.Repositories.Sql.EntityFramework.NetFramework.csproj", "{4536C116-0C7B-40AD-A2FC-3ED6D0EB1149}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dime.Repositories.Sql.EntityFramework.NetCore.Tests", "test\Dime.Repositories.Sql.EntityFramework.NetCore.Tests\Dime.Repositories.Sql.EntityFramework.NetCore.Tests.csproj", "{4C40805D-D4F3-4D49-B2C4-F464FE4CD833}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dime.Repositories.Sql.EntityFramework.Tests", "test\Dime.Repositories.Sql.EntityFramework.Tests\Dime.Repositories.Sql.EntityFramework.Tests.csproj", "{4C40805D-D4F3-4D49-B2C4-F464FE4CD833}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "providers", "providers", "{BF5B6AB2-33CF-494B-9D49-1A00ACF42729}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Dime.Repositories.Sql.EntityFramework.Shared", "providers\EntityFramework.Shared\Dime.Repositories.Sql.EntityFramework.Shared.shproj", "{E2C7ADE6-23D8-4897-A156-05DCD901E2D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dime.Repositories.Sql.EntityFramework.NetFramework.Tests", "test\Dime.Repositories.Sql.EntityFramework.NetFramework.Tests\Dime.Repositories.Sql.EntityFramework.NetFramework.Tests.csproj", "{719B5ACC-8EA5-47B7-A8DA-B54A47E5ACA4}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
providers\EntityFramework.Shared\Dime.Repositories.Sql.EntityFramework.Shared.projitems*{b501e673-cc10-4bff-a086-cff1df482816}*SharedItemsImports = 5
providers\EntityFramework.Shared\Dime.Repositories.Sql.EntityFramework.Shared.projitems*{e2c7ade6-23d8-4897-a156-05dcd901e2d0}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Expand All @@ -43,28 +33,17 @@ Global
{B501E673-CC10-4BFF-A086-CFF1DF482816}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B501E673-CC10-4BFF-A086-CFF1DF482816}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B501E673-CC10-4BFF-A086-CFF1DF482816}.Release|Any CPU.Build.0 = Release|Any CPU
{4536C116-0C7B-40AD-A2FC-3ED6D0EB1149}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4536C116-0C7B-40AD-A2FC-3ED6D0EB1149}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4536C116-0C7B-40AD-A2FC-3ED6D0EB1149}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4536C116-0C7B-40AD-A2FC-3ED6D0EB1149}.Release|Any CPU.Build.0 = Release|Any CPU
{4C40805D-D4F3-4D49-B2C4-F464FE4CD833}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C40805D-D4F3-4D49-B2C4-F464FE4CD833}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C40805D-D4F3-4D49-B2C4-F464FE4CD833}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C40805D-D4F3-4D49-B2C4-F464FE4CD833}.Release|Any CPU.Build.0 = Release|Any CPU
{719B5ACC-8EA5-47B7-A8DA-B54A47E5ACA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{719B5ACC-8EA5-47B7-A8DA-B54A47E5ACA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{719B5ACC-8EA5-47B7-A8DA-B54A47E5ACA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{719B5ACC-8EA5-47B7-A8DA-B54A47E5ACA4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B501E673-CC10-4BFF-A086-CFF1DF482816} = {BF5B6AB2-33CF-494B-9D49-1A00ACF42729}
{4536C116-0C7B-40AD-A2FC-3ED6D0EB1149} = {BF5B6AB2-33CF-494B-9D49-1A00ACF42729}
{4C40805D-D4F3-4D49-B2C4-F464FE4CD833} = {F753A01F-2E0C-4036-9DEF-6047253255D2}
{E2C7ADE6-23D8-4897-A156-05DCD901E2D0} = {BF5B6AB2-33CF-494B-9D49-1A00ACF42729}
{719B5ACC-8EA5-47B7-A8DA-B54A47E5ACA4} = {F753A01F-2E0C-4036-9DEF-6047253255D2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EFEF8275-DA5B-4493-8BB7-32E760B05267}
Expand Down
20 changes: 0 additions & 20 deletions src/Dime.Repositories.sln.DotSettings.user

This file was deleted.

6 changes: 0 additions & 6 deletions src/NuGet.Config

This file was deleted.

20 changes: 5 additions & 15 deletions src/core/Dime.Repositories.Sql/Dime.Repositories.Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<Authors>Dime Software</Authors>
<Version>2.0.0.0-alpha.38</Version>
<Version>2.0.0.0</Version>
<Authors>Dime Software</Authors>
<TargetFrameworks>net461;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<AssemblyName>Dime.Repositories.Sql</AssemblyName>
<PackageId>Dime.Repositories.Sql</PackageId>
<PackageIconUrl>https://cdn.dime-software.com/dime-software/logo-shape.png</PackageIconUrl>
Expand All @@ -19,7 +19,7 @@
<Description>Repository contracts with support for SQL databases</Description>
<IncludeSource>True</IncludeSource>
<IncludeSymbols>True</IncludeSymbols>
<Copyright>Copyright © 2022</Copyright>
<Copyright>Copyright © 2023</Copyright>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageProjectUrl>https://github.com/dimesoftware/repository</PackageProjectUrl>
<RepositoryUrl>https://github.com/dimesoftware/repository</RepositoryUrl>
Expand All @@ -31,17 +31,7 @@
<ProjectReference Include="..\Dime.Repositories\Dime.Repositories.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net461'">
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
</ItemGroup>

</Project>
9 changes: 0 additions & 9 deletions src/core/Dime.Repositories.Sql/IStoredProcedureRepository.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
using System.Collections.Generic;
using System.Data.Common;

#if NET461

using System.Data.SqlClient;

#else

using Microsoft.Data.SqlClient;

#endif

namespace Dime.Repositories
{
public interface IStoredProcedureRepository
Expand Down
11 changes: 3 additions & 8 deletions src/core/Dime.Repositories/Dime.Repositories.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<Authors>Dime Software</Authors>
<Version>2.0.0.0-alpha.48</Version>
<TargetFrameworks>net461;net7.0</TargetFrameworks>
<Version>2.0.0.0</Version>
<TargetFrameworks>net8.0</TargetFrameworks>
<AssemblyName>Dime.Repositories</AssemblyName>
<PackageId>Dime.Repositories</PackageId>
<PackageIconUrl>https://cdn.dime-software.com/dime-software/logo-shape.png</PackageIconUrl>
Expand All @@ -17,17 +17,12 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSource>True</IncludeSource>
<IncludeSymbols>True</IncludeSymbols>
<Copyright>Copyright © 2022</Copyright>
<Copyright>Copyright © 2023</Copyright>
<PackageProjectUrl>https://github.com/dimesoftware/repository</PackageProjectUrl>
<RepositoryUrl>https://github.com/dimesoftware/repository</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<LangVersion>latest</LangVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
</ItemGroup>

</Project>
10 changes: 0 additions & 10 deletions src/core/Dime.Repositories/Models/Order.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
namespace Dime.Repositories
{
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
public class Order<T> : IOrder<T>
{
public Order(string property, bool isAscending)
Expand All @@ -12,14 +8,8 @@ public Order(string property, bool isAscending)
IsAscending = isAscending;
}

/// <summary>
/// Gets or sets the sorting property
/// </summary>
public string Property { get; set; }

/// <summary>
/// Gets or sets the sorting direction
/// </summary>
public bool IsAscending { get; set; }

public void Deconstruct(out string property, out bool isAscending)
Expand Down
Loading

0 comments on commit c48e07b

Please sign in to comment.