Skip to content

Commit 08bca2f

Browse files
committed
Improve code and remove UoW from Handler #3 #4
1 parent 7f15540 commit 08bca2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1084
-49
lines changed

Diff for: .dockerignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.dockerignore
2+
.env
3+
.git
4+
.gitignore
5+
.vs
6+
.vscode
7+
*/bin
8+
*/obj
9+
**/.toolstarget

Diff for: build.cake

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var isWindows = IsRunningOnWindows();
1010
var libs = new List<string>{
1111
"./src/NetCoreKit.Utils/NetCoreKit.Utils.csproj",
1212
"./src/NetCoreKit.Domain/NetCoreKit.Domain.csproj",
13+
"./src/NetCoreKit.Infrastructure/NetCoreKit.Infrastructure.csproj",
1314
"./src/NetCoreKit.Infrastructure.AspNetCore/NetCoreKit.Infrastructure.AspNetCore.csproj",
1415
"./src/NetCoreKit.Infrastructure.AspNetCore.CleanArch/NetCoreKit.Infrastructure.AspNetCore.CleanArch.csproj",
1516
"./src/NetCoreKit.Infrastructure.AspNetCore.Miniservice/NetCoreKit.Infrastructure.AspNetCore.Miniservice.csproj",

Diff for: netcore-kit.sln

+56
Original file line numberDiff line numberDiff line change
@@ -39,44 +39,98 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
3939
EndProject
4040
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "__", "__", "{EE8515E4-F600-4699-A652-FE8E241B9A83}"
4141
EndProject
42+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreKit.Samples.TodoAPI", "samples\TodoApi\NetCoreKit.Samples.TodoAPI.csproj", "{07F7005A-062E-478D-93C0-3B7E1C42389E}"
43+
EndProject
44+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreKit.Infrastructure", "src\NetCoreKit.Infrastructure\NetCoreKit.Infrastructure.csproj", "{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}"
45+
EndProject
4246
Global
4347
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4448
Debug|Any CPU = Debug|Any CPU
49+
Debug|x86 = Debug|x86
4550
Release|Any CPU = Release|Any CPU
51+
Release|x86 = Release|x86
4652
EndGlobalSection
4753
GlobalSection(ProjectConfigurationPlatforms) = postSolution
4854
{B9235669-6FFC-4266-B103-851B07EC6E8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4955
{B9235669-6FFC-4266-B103-851B07EC6E8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
56+
{B9235669-6FFC-4266-B103-851B07EC6E8E}.Debug|x86.ActiveCfg = Debug|Any CPU
57+
{B9235669-6FFC-4266-B103-851B07EC6E8E}.Debug|x86.Build.0 = Debug|Any CPU
5058
{B9235669-6FFC-4266-B103-851B07EC6E8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
5159
{B9235669-6FFC-4266-B103-851B07EC6E8E}.Release|Any CPU.Build.0 = Release|Any CPU
60+
{B9235669-6FFC-4266-B103-851B07EC6E8E}.Release|x86.ActiveCfg = Release|Any CPU
61+
{B9235669-6FFC-4266-B103-851B07EC6E8E}.Release|x86.Build.0 = Release|Any CPU
5262
{CAF26917-0B10-4FB9-BD59-F792D21C2BD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5363
{CAF26917-0B10-4FB9-BD59-F792D21C2BD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{CAF26917-0B10-4FB9-BD59-F792D21C2BD8}.Debug|x86.ActiveCfg = Debug|Any CPU
65+
{CAF26917-0B10-4FB9-BD59-F792D21C2BD8}.Debug|x86.Build.0 = Debug|Any CPU
5466
{CAF26917-0B10-4FB9-BD59-F792D21C2BD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
5567
{CAF26917-0B10-4FB9-BD59-F792D21C2BD8}.Release|Any CPU.Build.0 = Release|Any CPU
68+
{CAF26917-0B10-4FB9-BD59-F792D21C2BD8}.Release|x86.ActiveCfg = Release|Any CPU
69+
{CAF26917-0B10-4FB9-BD59-F792D21C2BD8}.Release|x86.Build.0 = Release|Any CPU
5670
{29F1B230-7A1A-43DB-9294-D3A664220D8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5771
{29F1B230-7A1A-43DB-9294-D3A664220D8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
72+
{29F1B230-7A1A-43DB-9294-D3A664220D8C}.Debug|x86.ActiveCfg = Debug|Any CPU
73+
{29F1B230-7A1A-43DB-9294-D3A664220D8C}.Debug|x86.Build.0 = Debug|Any CPU
5874
{29F1B230-7A1A-43DB-9294-D3A664220D8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
5975
{29F1B230-7A1A-43DB-9294-D3A664220D8C}.Release|Any CPU.Build.0 = Release|Any CPU
76+
{29F1B230-7A1A-43DB-9294-D3A664220D8C}.Release|x86.ActiveCfg = Release|Any CPU
77+
{29F1B230-7A1A-43DB-9294-D3A664220D8C}.Release|x86.Build.0 = Release|Any CPU
6078
{F57C8FE9-DC9C-4858-8EA7-6AEF523557A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6179
{F57C8FE9-DC9C-4858-8EA7-6AEF523557A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
80+
{F57C8FE9-DC9C-4858-8EA7-6AEF523557A4}.Debug|x86.ActiveCfg = Debug|Any CPU
81+
{F57C8FE9-DC9C-4858-8EA7-6AEF523557A4}.Debug|x86.Build.0 = Debug|Any CPU
6282
{F57C8FE9-DC9C-4858-8EA7-6AEF523557A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
6383
{F57C8FE9-DC9C-4858-8EA7-6AEF523557A4}.Release|Any CPU.Build.0 = Release|Any CPU
84+
{F57C8FE9-DC9C-4858-8EA7-6AEF523557A4}.Release|x86.ActiveCfg = Release|Any CPU
85+
{F57C8FE9-DC9C-4858-8EA7-6AEF523557A4}.Release|x86.Build.0 = Release|Any CPU
6486
{E8AA73B0-2BFC-4D9F-8921-CE25A6EE49FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6587
{E8AA73B0-2BFC-4D9F-8921-CE25A6EE49FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
88+
{E8AA73B0-2BFC-4D9F-8921-CE25A6EE49FB}.Debug|x86.ActiveCfg = Debug|Any CPU
89+
{E8AA73B0-2BFC-4D9F-8921-CE25A6EE49FB}.Debug|x86.Build.0 = Debug|Any CPU
6690
{E8AA73B0-2BFC-4D9F-8921-CE25A6EE49FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
6791
{E8AA73B0-2BFC-4D9F-8921-CE25A6EE49FB}.Release|Any CPU.Build.0 = Release|Any CPU
92+
{E8AA73B0-2BFC-4D9F-8921-CE25A6EE49FB}.Release|x86.ActiveCfg = Release|Any CPU
93+
{E8AA73B0-2BFC-4D9F-8921-CE25A6EE49FB}.Release|x86.Build.0 = Release|Any CPU
6894
{86E10CC4-BAA0-459F-B0C9-3C6CE466DD9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6995
{86E10CC4-BAA0-459F-B0C9-3C6CE466DD9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
96+
{86E10CC4-BAA0-459F-B0C9-3C6CE466DD9B}.Debug|x86.ActiveCfg = Debug|Any CPU
97+
{86E10CC4-BAA0-459F-B0C9-3C6CE466DD9B}.Debug|x86.Build.0 = Debug|Any CPU
7098
{86E10CC4-BAA0-459F-B0C9-3C6CE466DD9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
7199
{86E10CC4-BAA0-459F-B0C9-3C6CE466DD9B}.Release|Any CPU.Build.0 = Release|Any CPU
100+
{86E10CC4-BAA0-459F-B0C9-3C6CE466DD9B}.Release|x86.ActiveCfg = Release|Any CPU
101+
{86E10CC4-BAA0-459F-B0C9-3C6CE466DD9B}.Release|x86.Build.0 = Release|Any CPU
72102
{FA666FF1-5453-481D-BBDD-842F151F9E75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73103
{FA666FF1-5453-481D-BBDD-842F151F9E75}.Debug|Any CPU.Build.0 = Debug|Any CPU
104+
{FA666FF1-5453-481D-BBDD-842F151F9E75}.Debug|x86.ActiveCfg = Debug|Any CPU
105+
{FA666FF1-5453-481D-BBDD-842F151F9E75}.Debug|x86.Build.0 = Debug|Any CPU
74106
{FA666FF1-5453-481D-BBDD-842F151F9E75}.Release|Any CPU.ActiveCfg = Release|Any CPU
75107
{FA666FF1-5453-481D-BBDD-842F151F9E75}.Release|Any CPU.Build.0 = Release|Any CPU
108+
{FA666FF1-5453-481D-BBDD-842F151F9E75}.Release|x86.ActiveCfg = Release|Any CPU
109+
{FA666FF1-5453-481D-BBDD-842F151F9E75}.Release|x86.Build.0 = Release|Any CPU
76110
{D6B29A97-1417-48A6-B141-74D57E5C8C16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77111
{D6B29A97-1417-48A6-B141-74D57E5C8C16}.Debug|Any CPU.Build.0 = Debug|Any CPU
112+
{D6B29A97-1417-48A6-B141-74D57E5C8C16}.Debug|x86.ActiveCfg = Debug|Any CPU
113+
{D6B29A97-1417-48A6-B141-74D57E5C8C16}.Debug|x86.Build.0 = Debug|Any CPU
78114
{D6B29A97-1417-48A6-B141-74D57E5C8C16}.Release|Any CPU.ActiveCfg = Release|Any CPU
79115
{D6B29A97-1417-48A6-B141-74D57E5C8C16}.Release|Any CPU.Build.0 = Release|Any CPU
116+
{D6B29A97-1417-48A6-B141-74D57E5C8C16}.Release|x86.ActiveCfg = Release|Any CPU
117+
{D6B29A97-1417-48A6-B141-74D57E5C8C16}.Release|x86.Build.0 = Release|Any CPU
118+
{07F7005A-062E-478D-93C0-3B7E1C42389E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119+
{07F7005A-062E-478D-93C0-3B7E1C42389E}.Debug|Any CPU.Build.0 = Debug|Any CPU
120+
{07F7005A-062E-478D-93C0-3B7E1C42389E}.Debug|x86.ActiveCfg = Debug|Any CPU
121+
{07F7005A-062E-478D-93C0-3B7E1C42389E}.Debug|x86.Build.0 = Debug|Any CPU
122+
{07F7005A-062E-478D-93C0-3B7E1C42389E}.Release|Any CPU.ActiveCfg = Release|Any CPU
123+
{07F7005A-062E-478D-93C0-3B7E1C42389E}.Release|Any CPU.Build.0 = Release|Any CPU
124+
{07F7005A-062E-478D-93C0-3B7E1C42389E}.Release|x86.ActiveCfg = Release|Any CPU
125+
{07F7005A-062E-478D-93C0-3B7E1C42389E}.Release|x86.Build.0 = Release|Any CPU
126+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
127+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
128+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}.Debug|x86.ActiveCfg = Debug|Any CPU
129+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}.Debug|x86.Build.0 = Debug|Any CPU
130+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
131+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}.Release|x86.ActiveCfg = Release|Any CPU
133+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F}.Release|x86.Build.0 = Release|Any CPU
80134
EndGlobalSection
81135
GlobalSection(SolutionProperties) = preSolution
82136
HideSolutionNode = FALSE
@@ -91,6 +145,8 @@ Global
91145
{FA666FF1-5453-481D-BBDD-842F151F9E75} = {6CF50533-EBD6-47B1-9AD9-9EBBFF3AC887}
92146
{D6B29A97-1417-48A6-B141-74D57E5C8C16} = {6CF50533-EBD6-47B1-9AD9-9EBBFF3AC887}
93147
{A1CCC105-67B3-45AE-9A74-DD6716521708} = {EE8515E4-F600-4699-A652-FE8E241B9A83}
148+
{07F7005A-062E-478D-93C0-3B7E1C42389E} = {92D6FD73-B95C-4CBB-A48E-047672EB4E77}
149+
{EE16B7AA-67D5-463E-A24F-6221DBD80A5F} = {6CF50533-EBD6-47B1-9AD9-9EBBFF3AC887}
94150
EndGlobalSection
95151
GlobalSection(ExtensibilityGlobals) = postSolution
96152
SolutionGuid = {B9325AE8-21A8-4D46-9B04-38BD2BC35C0F}

Diff for: samples/TodoApi/.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!src
3+
!*.sln
4+
**/bin
5+
**/obj

Diff for: samples/TodoApi/Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM microsoft/dotnet:2.1.2-aspnetcore-runtime-alpine AS base
2+
WORKDIR /app
3+
4+
ARG service_version
5+
ENV SERVICE_VERSION ${service_version:-0.0.1}
6+
7+
ARG api_version
8+
ENV API_VERSION ${api_version:-1.0}
9+
10+
ENV ASPNETCORE_URLS http://+:5001
11+
EXPOSE 5001
12+
13+
FROM microsoft/dotnet:2.1.302-sdk-alpine AS build
14+
WORKDIR /src
15+
COPY . .
16+
17+
WORKDIR /src/src/samples
18+
19+
RUN dotnet restore -nowarn:msb3202,nu1503
20+
RUN dotnet build --no-restore -c Release -o /app
21+
22+
FROM build AS publish
23+
RUN dotnet publish --no-restore -c Release -o /app
24+
25+
FROM base AS final
26+
WORKDIR /app
27+
COPY --from=publish /app .
28+
ENTRYPOINT ["dotnet", "Company.Application.samples.dll"]

Diff for: samples/TodoApi/Domain/Todo.cs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
using NetCoreKit.Domain;
4+
5+
namespace NetCoreKit.Samples.TodoAPI.Domain
6+
{
7+
public sealed class Todo : EntityBase
8+
{
9+
internal Todo(string title)
10+
: this(Guid.NewGuid(), title)
11+
{
12+
}
13+
14+
public Todo(Guid id, string title) : base(id)
15+
{
16+
Title = title;
17+
}
18+
19+
public static Todo Load(string title)
20+
{
21+
return new Todo(title);
22+
}
23+
24+
public static Todo Load(Guid id, string title)
25+
{
26+
return new Todo(id, title);
27+
}
28+
29+
public int? Order { get; private set; } = 1;
30+
[Required] public string Title { get; private set; }
31+
public bool? Completed { get; private set; } = false;
32+
33+
public Todo ChangeTitle(string title)
34+
{
35+
if(string.IsNullOrEmpty(title))
36+
throw new DomainException("Order is null or empty.");
37+
Title = title;
38+
return this;
39+
}
40+
41+
public Todo ChangeOrder(int order)
42+
{
43+
if (order <= 0)
44+
throw new DomainException("Order could be greater than zero.");
45+
Order = order;
46+
return this;
47+
}
48+
49+
public Todo ChangeToCompleted()
50+
{
51+
Completed = true;
52+
return this;
53+
}
54+
}
55+
}

Diff for: samples/TodoApi/Dtos/TodoDto.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace NetCoreKit.Samples.TodoAPI.Dtos
4+
{
5+
public class TodoDto
6+
{
7+
public Guid Id { get; set; }
8+
public string Title { get; set; }
9+
public int Order { get; set; }
10+
public bool Completed { get; set; }
11+
}
12+
}

Diff for: samples/TodoApi/Extensions/TodoExtensions.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using NetCoreKit.Samples.TodoAPI.Domain;
2+
using NetCoreKit.Samples.TodoAPI.Dtos;
3+
4+
namespace NetCoreKit.Samples.TodoAPI.Extensions
5+
{
6+
public static class TodoExtensions
7+
{
8+
public static TodoDto ToDto(this Todo todo)
9+
{
10+
return new TodoDto
11+
{
12+
Id = todo.Id,
13+
Title = todo.Title,
14+
Completed = todo.Completed ?? false,
15+
Order = todo.Order ?? 1
16+
};
17+
}
18+
}
19+
}

Diff for: samples/TodoApi/Infrastructure/Db/TodoDbContext.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using NetCoreKit.Infrastructure.EfCore.Db;
3+
4+
namespace NetCoreKit.Samples.TodoAPI.Infrastructure.Db
5+
{
6+
public class TodoDbContext : ApplicationDbContext
7+
{
8+
public TodoDbContext(DbContextOptions options) : base(options)
9+
{
10+
}
11+
}
12+
}

Diff for: samples/TodoApi/Migrations/20180817091043_InitTodoDb.Designer.cs

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
namespace NetCoreKit.Samples.TodoAPI.Migrations
5+
{
6+
public partial class InitTodoDb : Migration
7+
{
8+
protected override void Up(MigrationBuilder migrationBuilder)
9+
{
10+
migrationBuilder.CreateTable(
11+
name: "Todos",
12+
columns: table => new
13+
{
14+
Id = table.Column<Guid>(nullable: false),
15+
Created = table.Column<DateTime>(nullable: false),
16+
Updated = table.Column<DateTime>(nullable: false),
17+
Order = table.Column<int>(nullable: true),
18+
Title = table.Column<string>(nullable: false),
19+
Completed = table.Column<bool>(nullable: true)
20+
},
21+
constraints: table =>
22+
{
23+
table.PrimaryKey("PK_Todos", x => x.Id);
24+
});
25+
}
26+
27+
protected override void Down(MigrationBuilder migrationBuilder)
28+
{
29+
migrationBuilder.DropTable(
30+
name: "Todos");
31+
}
32+
}
33+
}
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// <auto-generated />
2+
using System;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Infrastructure;
5+
using Microsoft.EntityFrameworkCore.Metadata;
6+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7+
using NetCoreKit.Samples.TodoAPI.Infrastructure.Db;
8+
9+
namespace NetCoreKit.Samples.TodoAPI.Migrations
10+
{
11+
[DbContext(typeof(TodoDbContext))]
12+
partial class TodoDbContextModelSnapshot : ModelSnapshot
13+
{
14+
protected override void BuildModel(ModelBuilder modelBuilder)
15+
{
16+
#pragma warning disable 612, 618
17+
modelBuilder
18+
.HasAnnotation("ProductVersion", "2.1.1-rtm-30846")
19+
.HasAnnotation("Relational:MaxIdentifierLength", 128)
20+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
21+
22+
modelBuilder.Entity("NetCoreKit.Samples.TodoAPI.Domain.Todo", b =>
23+
{
24+
b.Property<Guid>("Id")
25+
.ValueGeneratedOnAdd();
26+
27+
b.Property<bool?>("Completed");
28+
29+
b.Property<DateTime>("Created");
30+
31+
b.Property<int?>("Order");
32+
33+
b.Property<string>("Title")
34+
.IsRequired();
35+
36+
b.Property<DateTime>("Updated");
37+
38+
b.HasKey("Id");
39+
40+
b.ToTable("Todos");
41+
});
42+
#pragma warning restore 612, 618
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)