.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using VizhTalk.BuildingBlocks.Application.Data;
|
||||
using Dapper;
|
||||
using System.Data;
|
||||
|
||||
namespace VizhTalk.Learning.Infrastructure.Dapper;
|
||||
|
||||
public class GenericDapper<T> : IGenericDapper<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly IDbConnection connection;
|
||||
public GenericDapper(ISqlConnectionFactory sqlConnectionFactory)
|
||||
{
|
||||
connection = sqlConnectionFactory.GetOpenConnection();
|
||||
}
|
||||
public async Task<T?> GetAsync(string sql, object? param = null)
|
||||
{
|
||||
return await connection.QueryFirstOrDefaultAsync<T>(sql, param);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> GetAllAsync(string sql, object? param = null)
|
||||
{
|
||||
return await connection.QueryAsync<T>(sql, param);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
connection.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VizhTalk.Learning.Domain.Entities;
|
||||
using VizhTalk.Learning.Domain.ValueObjects;
|
||||
|
||||
namespace VizhTalk.Learning.Infrastructure.EF.Configurations
|
||||
{
|
||||
@@ -20,13 +21,9 @@ namespace VizhTalk.Learning.Infrastructure.EF.Configurations
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasConversion(x => x.Value, x => new Domain.TypeIds.LanguageId(x));
|
||||
|
||||
builder.OwnsOne(x => x.Title, op =>
|
||||
{
|
||||
op.Property(x => x.Value)
|
||||
.HasColumnName("Title")
|
||||
builder.Property(x => x.Title)
|
||||
.HasConversion(x => x.Value, x => new LanguageTitle(x))
|
||||
.HasMaxLength(60);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using VizhTalk.BuildingBlocks.Infrastructure.DomainEventsDispatching;
|
||||
using VizhTalk.Learning.Application;
|
||||
using VizhTalk.Learning.Application.Mappers;
|
||||
using VizhTalk.Learning.Infrastructure.Configuration;
|
||||
using VizhTalk.Learning.Infrastructure.Dapper;
|
||||
using VizhTalk.Learning.Infrastructure.EF;
|
||||
using VizhTalk.Learning.Infrastructure.Outbox;
|
||||
|
||||
@@ -35,6 +36,7 @@ public static class LearningStartup
|
||||
services.AddScoped<IDomainEventsAccessor, DomainEventsAccessor>();
|
||||
services.AddScoped<IDomainEventsDispatcher, DomainEventsDispatcher>();
|
||||
services.AddScoped<IDomainNotificationsMapper, DomainNotificationsMapper>();
|
||||
services.AddScoped(typeof(IGenericDapper<>),typeof(GenericDapper<>));
|
||||
services.AddScoped(sp => domainNotificationsMap);
|
||||
services.Scan(scan => scan.
|
||||
FromAssemblies(Assemblies.Application, Assemblies.Infrastructure)
|
||||
|
||||
+10
-30
@@ -11,8 +11,8 @@ using VizhTalk.Learning.Infrastructure.EF;
|
||||
namespace VizhTalk.Learning.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(LearningDbContext))]
|
||||
[Migration("20250901180950_Initial")]
|
||||
partial class Initial
|
||||
[Migration("20250902200044_Inital")]
|
||||
partial class Inital
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -27,11 +27,11 @@ namespace VizhTalk.Learning.Infrastructure.Migrations
|
||||
|
||||
modelBuilder.Entity("VizhTalk.Learning.Domain.Entities.Language", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
@@ -39,35 +39,15 @@ namespace VizhTalk.Learning.Infrastructure.Migrations
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("nvarchar(60)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Languages", "Learning");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("VizhTalk.Learning.Domain.Entities.Language", b =>
|
||||
{
|
||||
b.OwnsOne("VizhTalk.Learning.Domain.ValueObjects.LanguageTitle", "Title", b1 =>
|
||||
{
|
||||
b1.Property<long>("LanguageId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("nvarchar(60)")
|
||||
.HasColumnName("Title");
|
||||
|
||||
b1.HasKey("LanguageId");
|
||||
|
||||
b1.ToTable("LanguageTitles", "Learning");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("LanguageId");
|
||||
});
|
||||
|
||||
b.Navigation("Title")
|
||||
.IsRequired();
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
+3
-26
@@ -5,7 +5,7 @@
|
||||
namespace VizhTalk.Learning.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Initial : Migration
|
||||
public partial class Inital : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@@ -18,8 +18,9 @@ namespace VizhTalk.Learning.Infrastructure.Migrations
|
||||
schema: "Learning",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false)
|
||||
},
|
||||
@@ -27,35 +28,11 @@ namespace VizhTalk.Learning.Infrastructure.Migrations
|
||||
{
|
||||
table.PrimaryKey("PK_Languages", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LanguageTitles",
|
||||
schema: "Learning",
|
||||
columns: table => new
|
||||
{
|
||||
LanguageId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Title = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LanguageTitles", x => x.LanguageId);
|
||||
table.ForeignKey(
|
||||
name: "FK_LanguageTitles_Languages_LanguageId",
|
||||
column: x => x.LanguageId,
|
||||
principalSchema: "Learning",
|
||||
principalTable: "Languages",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "LanguageTitles",
|
||||
schema: "Learning");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Languages",
|
||||
schema: "Learning");
|
||||
@@ -24,11 +24,11 @@ namespace VizhTalk.Learning.Infrastructure.Migrations
|
||||
|
||||
modelBuilder.Entity("VizhTalk.Learning.Domain.Entities.Language", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
@@ -36,35 +36,15 @@ namespace VizhTalk.Learning.Infrastructure.Migrations
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("nvarchar(60)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Languages", "Learning");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("VizhTalk.Learning.Domain.Entities.Language", b =>
|
||||
{
|
||||
b.OwnsOne("VizhTalk.Learning.Domain.ValueObjects.LanguageTitle", "Title", b1 =>
|
||||
{
|
||||
b1.Property<long>("LanguageId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("nvarchar(60)")
|
||||
.HasColumnName("Title");
|
||||
|
||||
b1.HasKey("LanguageId");
|
||||
|
||||
b1.ToTable("LanguageTitles", "Learning");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("LanguageId");
|
||||
});
|
||||
|
||||
b.Navigation("Title")
|
||||
.IsRequired();
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.66" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.19">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
Reference in New Issue
Block a user