Skip to content

Commit

Permalink
ef core unit of work version 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alelho committed Mar 17, 2024
1 parent 80e1c7d commit 0e71b17
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 101 deletions.
5 changes: 5 additions & 0 deletions ef-core-data-access.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCoreDataAccess.API", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCoreUnitOfWork", "src\EFCoreUnitOfWork\EFCoreUnitOfWork.csproj", "{BABC98F0-B85E-4635-A34D-51BA7F3C0542}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FB5252DA-1CF0-45AE-9D19-4C243DA8D800}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "7.0.406",
"rollForward": "latestFeature"
}
}
6 changes: 3 additions & 3 deletions src/EFCoreUnitOfWork/EFCoreUnitOfWork.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Alelho;AC Technology</Authors>
<PackageProjectUrl>https://github.com/Alelho/ef-core-unit-of-work</PackageProjectUrl>
Expand All @@ -15,8 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.16" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions src/Sample/EFCoreDataAccess.API/Configurations/Api.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;

namespace EFCoreDataAccess.API.Configurations
{
public static class Api
{
public static void AddApi(this IServiceCollection services)
{
services.AddControllers().
AddJsonOptions(opt =>
{
opt.JsonSerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase;
opt.JsonSerializerOptions.WriteIndented = true;
opt.JsonSerializerOptions.MaxDepth = 10;
opt.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
opt.JsonSerializerOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull;
opt.JsonSerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter());
});

services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "EFCoreDataAccess.API", Version = "v1" });
});
}

public static void ConfigureApi(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "EFCoreDataAccess.API v1"));
}

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
40 changes: 40 additions & 0 deletions src/Sample/EFCoreDataAccess.API/Configurations/Database.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using EFCoreDataAccess.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using EFCoreUnitOfWork.Extensions;
using System.Diagnostics;
using Microsoft.AspNetCore.Builder;
using System;

namespace EFCoreDataAccess.API.Configurations
{
public static class Database
{
public static void AddDatabase(this IServiceCollection services)
{
var connectionString = @"Server=localhost;Database=EFCoreUnitOfWork;Uid=root;Pwd=123456;";

// Register DbContext into DI container
// It can use SQL Server, PostgreSQL instead of MySQL
services.AddDbContext<EmployeeDbContext>(options =>
options.UseMySql(connectionString, serverVersion: ServerVersion.AutoDetect(connectionString))
.LogTo(msg => Debug.WriteLine(msg), LogLevel.Error));

// Add unit of work into DI container.
// This is an exetensions from the EfCoreUnitOfWork package
services.AddUnitOfWork<EmployeeDbContext>();
}

public static void ConfigureDatabase(IApplicationBuilder app)
{
RunMigrate(app.ApplicationServices);
}

private static void RunMigrate(IServiceProvider serviceProvider)
{
var dbContext = serviceProvider.CreateScope().ServiceProvider.GetService<EmployeeDbContext>();
dbContext.Database.Migrate();
}
}
}
14 changes: 10 additions & 4 deletions src/Sample/EFCoreDataAccess.API/EFCoreDataAccess.API.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.7">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -27,4 +27,10 @@
</Content>
</ItemGroup>

<ItemGroup>
<None Update="Properties\launchSettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/Sample/EFCoreDataAccess.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using EFCoreDataAccess.API;
using EFCoreDataAccess.API.Configurations;
using Microsoft.AspNetCore.Builder;

var builder = WebApplication.CreateBuilder(args);

var startup = new Startup(builder.Configuration);

startup.ConfigureServices(builder.Services);
builder.Services.AddApi();
builder.Services.AddDatabase();

var app = builder.Build();

startup.Configure(app, app.Environment);
Api.ConfigureApi(app, app.Environment);
Database.ConfigureDatabase(app);

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:14796",
"sslPort": 44321
"applicationUrl": "http://localhost:14796"
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"useSSL": false,
"httpPort": 5000,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
77 changes: 0 additions & 77 deletions src/Sample/EFCoreDataAccess.API/Startup.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/Sample/EFCoreDataAccess.Data/EFCoreDataAccess.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.7" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.16" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Sample/EFCoreDataAccess.Data/EmployeeDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;

namespace EFCoreDataAccess.Data
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sample/EFCoreDataAccess.Data/Mappings/AddressMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AddressMap : IEntityTypeConfiguration<Address>
public void Configure(EntityTypeBuilder<Address> builder)
{
builder.ToTable("Addresses");

builder.HasKey(o => o.Id);

builder.Property(o => o.State)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions tests/EFCoreDataAccess.Tests/EFCoreUnitOfWork.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -11,9 +11,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -22,8 +22,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EFCoreUnitOfWork\EFCoreUnitOfWork.csproj" />
<ProjectReference Include="..\..\src\Sample\EFCoreDataAccess.Data\EFCoreDataAccess.Data.csproj" />
<ProjectReference Include="..\..\src\Sample\EFCoreDataAccess.Models\EFCoreDataAccess.Models.csproj" />
</ItemGroup>

</Project>

0 comments on commit 0e71b17

Please sign in to comment.