Skip to content

Commit

Permalink
Feature/migration to net8 (#5)
Browse files Browse the repository at this point in the history
* Upgrade the projects to the latest version of .net

* Update the version number

* Update the builds
  • Loading branch information
moattarwork authored Feb 25, 2024
1 parent 2fce465 commit 766135c
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: "6.0.x"
dotnet-version: "8.0.x"
- name: Install dependencies
run: dotnet restore src

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: "6.0.x"
dotnet-version: "8.0.x"
- name: Install dependencies
run: dotnet restore src
- name: Use GitVersion
Expand Down
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
next-version: 1.0.1
next-version: 2.0.0
mode: Mainline
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
12 changes: 6 additions & 6 deletions src/LittleBlocks.Ef.Testing/LittleBlocks.Ef.Testing.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Mohammad Moattar</Authors>
<Company>LittleBlocks</Company>
<Description>LittleBlocks support for testing projects for UnitOfWork and Ef Core</Description>
<PackageProjectUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</PackageProjectUrl>
<RepositoryUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</RepositoryUrl>
<Version>1.0.0</Version>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
<PackageIcon>Logo.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="LittleBlocks" Version="1.0.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="LittleBlocks" Version="2.0.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.Ef\LittleBlocks.Ef.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Mohammad Moattar</Authors>
<Company>LittleBlocks</Company>
<Description>LittleBlocks support for entity framework core and UnitOfWork</Description>
<PackageProjectUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</PackageProjectUrl>
<RepositoryUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</RepositoryUrl>
<Version>1.0.0</Version>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/LittleBlocks.Ef.UnitOfWork/Extensions/PagingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class PagingOptions

public PagingOptions(int pageIndex, int pageSize = DefaultPageSize)
{
if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize));
if (pageIndex <= 0) throw new ArgumentOutOfRangeException(nameof(pageIndex));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(pageSize);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(pageIndex);

PageIndex = pageIndex;
PageSize = pageSize;
Expand Down
14 changes: 7 additions & 7 deletions src/LittleBlocks.Ef.UnitOfWork/Extensions/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ public static class QueryableExtensions
{
public static IQueryable<T> PagedBy<T>(this IQueryable<T> queryable, PagingOptions options)
{
if (queryable == null) throw new ArgumentNullException(nameof(queryable));
if (options == null) throw new ArgumentNullException(nameof(options));
ArgumentNullException.ThrowIfNull(queryable);
ArgumentNullException.ThrowIfNull(options);

return queryable.PagedBy(options.PageIndex, options.PageSize);
}

public static IQueryable<T> PagedBy<T>(this IQueryable<T> queryable, int pageIndex, int pageSize)
{
if (queryable == null) throw new ArgumentNullException(nameof(queryable));
if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex));
if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize));
ArgumentNullException.ThrowIfNull(queryable);
ArgumentOutOfRangeException.ThrowIfNegative(pageIndex);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(pageSize);

return queryable.Skip(pageIndex * pageSize).Take(pageSize);
}

public static IQueryable<TResult> ProjectTo<T, TResult>(this IQueryable<T> queryable, Func<T, TResult> projection)
{
if (queryable == null) throw new ArgumentNullException(nameof(queryable));
if (projection == null) throw new ArgumentNullException(nameof(projection));
ArgumentNullException.ThrowIfNull(queryable);
ArgumentNullException.ThrowIfNull(projection);

return queryable.Select(m => projection(m));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Mohammad Moattar</Authors>
<Company>LittleBlocks</Company>
<Description>LittleBlocks support for entity framework core and UnitOfWork</Description>
<PackageProjectUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</PackageProjectUrl>
<RepositoryUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</RepositoryUrl>
<Version>1.0.0</Version>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
<PackageIcon>Logo.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.AutoHistory" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<None Update="Logo.png">
Expand Down
7 changes: 3 additions & 4 deletions src/LittleBlocks.Ef.UnitOfWork/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@

namespace LittleBlocks.Ef.UnitOfWork
{
public sealed class UnitOfWork<TContext> : IRepositoryFactory, IUnitOfWork<TContext> where TContext : DbContext
public sealed class UnitOfWork<TContext>(TContext context) : IRepositoryFactory, IUnitOfWork<TContext>
where TContext : DbContext
{
private bool _disposed;
private Dictionary<Type, object> _repositories;

public UnitOfWork(TContext context) => DbContext = context ?? throw new ArgumentNullException(nameof(context));

public TContext DbContext { get; }
public TContext DbContext { get; } = context ?? throw new ArgumentNullException(nameof(context));

public IRepository<TEntity> GetRepository<TEntity>(bool hasCustomRepository = false) where TEntity : class
{
Expand Down
14 changes: 7 additions & 7 deletions src/LittleBlocks.Ef.UnitTests/LittleBlocks.Ef.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 2 additions & 0 deletions src/LittleBlocks.Ef.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extras", "Extras", "{966C50CB-3F74-442F-842D-164645690476}"
ProjectSection(SolutionItems) = preProject
..\GitVersion.yml = ..\GitVersion.yml
..\.github\workflows\release.yml = ..\.github\workflows\release.yml
..\.github\workflows\ci.yml = ..\.github\workflows\ci.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleBlocks.Ef.UnitOfWork", "LittleBlocks.Ef.UnitOfWork\LittleBlocks.Ef.UnitOfWork.csproj", "{E9B92105-F4C6-42B5-B3CF-64FA80486E93}"
Expand Down
10 changes: 3 additions & 7 deletions src/LittleBlocks.Ef/DbContextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@

namespace LittleBlocks.Ef;

public abstract class DbContextBase : DbContext
public abstract class DbContextBase(DbContextOptions options, IOperationContext operationContext)
: DbContext(options)
{
private readonly IOperationContext _operationContext;

protected DbContextBase(DbContextOptions options, IOperationContext operationContext) : base(options)
{
_operationContext = operationContext ?? throw new ArgumentNullException(nameof(operationContext));
}
private readonly IOperationContext _operationContext = operationContext ?? throw new ArgumentNullException(nameof(operationContext));

public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
Expand Down
2 changes: 1 addition & 1 deletion src/LittleBlocks.Ef/DbContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static IServiceCollection AddSqlDbContext<TDbContext>(this IServiceCollec
public static IServiceCollection AddSqlDbContext<TDbContext>(this IServiceCollection services,
string connectionString, Action<SqlServerDbContextOptionsBuilder> sqlOptionsAction) where TDbContext : DbContext
{
if (services == null) throw new ArgumentNullException(nameof(services));
ArgumentNullException.ThrowIfNull(services);

services.AddDbContext<TDbContext>(options => options.UseSqlServer(connectionString, sqlOptionsAction));
services.AddUnitOfWork<TDbContext>();
Expand Down
2 changes: 1 addition & 1 deletion src/LittleBlocks.Ef/Extensions/PrincipalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static string GetUserName(this IPrincipal principal)
if (!string.IsNullOrWhiteSpace(identity.Name))
return identity.Name;

if (!(identity is ClaimsIdentity claimsIdentity))
if (identity is not ClaimsIdentity claimsIdentity)
return AnonymousUser;

var claim = claimsIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name);
Expand Down
16 changes: 8 additions & 8 deletions src/LittleBlocks.Ef/LittleBlocks.Ef.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Mohammad Moattar</Authors>
<Company>LittleBlocks</Company>
<Description>LittleBlocks support for entity framework core and UnitOfWork</Description>
<PackageProjectUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</PackageProjectUrl>
<RepositoryUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</RepositoryUrl>
<Version>1.0.0</Version>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
<PackageIcon>Logo.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LittleBlocks.Extensions" Version="1.0.1" />
<PackageReference Include="LittleBlocks.Http" Version="1.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.12">
<PackageReference Include="LittleBlocks.Extensions" Version="2.0.0" />
<PackageReference Include="LittleBlocks.Http" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.Ef.UnitOfWork\LittleBlocks.Ef.UnitOfWork.csproj" />
Expand Down

0 comments on commit 766135c

Please sign in to comment.