diff --git a/Address Directory/Persistence/Migrations/20241208232209_mig1.Designer.cs b/Address Directory/Persistence/Migrations/20241208232209_mig1.Designer.cs
deleted file mode 100644
index 3a54be3..0000000
--- a/Address Directory/Persistence/Migrations/20241208232209_mig1.Designer.cs
+++ /dev/null
@@ -1,137 +0,0 @@
-//
-using System;
-using System.Collections.Generic;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using Persistence;
-
-#nullable disable
-
-namespace Persistence.Migrations
-{
- [DbContext(typeof(RepositoryDbContext))]
- [Migration("20241208232209_mig1")]
- partial class mig1
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "9.0.0")
- .HasAnnotation("Relational:MaxIdentifierLength", 63);
-
- NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
-
- modelBuilder.Entity("Domain.Entities.City", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.Property("Name")
- .IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
-
- b.Property("RegionId")
- .HasColumnType("uuid");
-
- b.HasKey("Id");
-
- b.HasIndex("RegionId");
-
- b.ToTable("Cities");
- });
-
- modelBuilder.Entity("Domain.Entities.Region", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.Property("Code")
- .HasColumnType("integer");
-
- b.Property("Name")
- .IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
-
- b.HasKey("Id");
-
- b.ToTable("Regions");
- });
-
- modelBuilder.Entity("Domain.Entities.Street", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.Property("CityId")
- .HasColumnType("uuid");
-
- b.PrimitiveCollection>("HouseNumbers")
- .IsRequired()
- .HasColumnType("integer[]");
-
- b.Property("Index")
- .HasColumnType("integer");
-
- b.Property("Name")
- .IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
-
- b.Property("OkatoCode")
- .HasColumnType("integer");
-
- b.Property("TaxCode")
- .HasColumnType("integer");
-
- b.HasKey("Id");
-
- b.HasIndex("CityId");
-
- b.ToTable("Streets");
- });
-
- modelBuilder.Entity("Domain.Entities.City", b =>
- {
- b.HasOne("Domain.Entities.Region", "Region")
- .WithMany("Cities")
- .HasForeignKey("RegionId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Region");
- });
-
- modelBuilder.Entity("Domain.Entities.Street", b =>
- {
- b.HasOne("Domain.Entities.City", "City")
- .WithMany("Streets")
- .HasForeignKey("CityId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("City");
- });
-
- modelBuilder.Entity("Domain.Entities.City", b =>
- {
- b.Navigation("Streets");
- });
-
- modelBuilder.Entity("Domain.Entities.Region", b =>
- {
- b.Navigation("Cities");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/Address Directory/Persistence/Migrations/20241208232448_mig2.cs b/Address Directory/Persistence/Migrations/20241208232448_mig2.cs
deleted file mode 100644
index 292ff89..0000000
--- a/Address Directory/Persistence/Migrations/20241208232448_mig2.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace Persistence.Migrations
-{
- ///
- public partial class mig2 : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
-
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
-
- }
- }
-}
diff --git a/Address Directory/Persistence/Migrations/20241208232448_mig2.Designer.cs b/Address Directory/Persistence/Migrations/20241210151814_mig2.Designer.cs
similarity index 91%
rename from Address Directory/Persistence/Migrations/20241208232448_mig2.Designer.cs
rename to Address Directory/Persistence/Migrations/20241210151814_mig2.Designer.cs
index f90caa1..b97fbb8 100644
--- a/Address Directory/Persistence/Migrations/20241208232448_mig2.Designer.cs
+++ b/Address Directory/Persistence/Migrations/20241210151814_mig2.Designer.cs
@@ -13,7 +13,7 @@ using Persistence;
namespace Persistence.Migrations
{
[DbContext(typeof(RepositoryDbContext))]
- [Migration("20241208232448_mig2")]
+ [Migration("20241210151814_mig2")]
partial class mig2
{
///
@@ -34,8 +34,7 @@ namespace Persistence.Migrations
b.Property("Name")
.IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
+ .HasColumnType("text");
b.Property("RegionId")
.HasColumnType("uuid");
@@ -58,8 +57,7 @@ namespace Persistence.Migrations
b.Property("Name")
.IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
+ .HasColumnType("text");
b.HasKey("Id");
@@ -84,8 +82,7 @@ namespace Persistence.Migrations
b.Property("Name")
.IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
+ .HasColumnType("text");
b.Property("OkatoCode")
.HasColumnType("integer");
diff --git a/Address Directory/Persistence/Migrations/20241208232209_mig1.cs b/Address Directory/Persistence/Migrations/20241210151814_mig2.cs
similarity index 89%
rename from Address Directory/Persistence/Migrations/20241208232209_mig1.cs
rename to Address Directory/Persistence/Migrations/20241210151814_mig2.cs
index 438361f..72207a8 100644
--- a/Address Directory/Persistence/Migrations/20241208232209_mig1.cs
+++ b/Address Directory/Persistence/Migrations/20241210151814_mig2.cs
@@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Persistence.Migrations
{
///
- public partial class mig1 : Migration
+ public partial class mig2 : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
@@ -17,7 +17,7 @@ namespace Persistence.Migrations
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
- Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
+ Name = table.Column(type: "text", nullable: false),
Code = table.Column(type: "integer", nullable: false)
},
constraints: table =>
@@ -30,7 +30,7 @@ namespace Persistence.Migrations
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
- Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
+ Name = table.Column(type: "text", nullable: false),
RegionId = table.Column(type: "uuid", nullable: false)
},
constraints: table =>
@@ -49,7 +49,7 @@ namespace Persistence.Migrations
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
- Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
+ Name = table.Column(type: "text", nullable: false),
HouseNumbers = table.Column>(type: "integer[]", nullable: false),
Index = table.Column(type: "integer", nullable: false),
OkatoCode = table.Column(type: "integer", nullable: false),
diff --git a/Address Directory/Persistence/Migrations/RepositoryDbContextModelSnapshot.cs b/Address Directory/Persistence/Migrations/RepositoryDbContextModelSnapshot.cs
index 779a82d..d27f773 100644
--- a/Address Directory/Persistence/Migrations/RepositoryDbContextModelSnapshot.cs
+++ b/Address Directory/Persistence/Migrations/RepositoryDbContextModelSnapshot.cs
@@ -31,8 +31,7 @@ namespace Persistence.Migrations
b.Property("Name")
.IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
+ .HasColumnType("text");
b.Property("RegionId")
.HasColumnType("uuid");
@@ -55,8 +54,7 @@ namespace Persistence.Migrations
b.Property("Name")
.IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
+ .HasColumnType("text");
b.HasKey("Id");
@@ -81,8 +79,7 @@ namespace Persistence.Migrations
b.Property("Name")
.IsRequired()
- .HasMaxLength(100)
- .HasColumnType("character varying(100)");
+ .HasColumnType("text");
b.Property("OkatoCode")
.HasColumnType("integer");
diff --git a/Address Directory/Persistence/RepositoryDbContext.cs b/Address Directory/Persistence/RepositoryDbContext.cs
index b34d94a..6fc6740 100644
--- a/Address Directory/Persistence/RepositoryDbContext.cs
+++ b/Address Directory/Persistence/RepositoryDbContext.cs
@@ -5,27 +5,13 @@ namespace Persistence
{
public class RepositoryDbContext : DbContext
{
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- if (optionsBuilder.IsConfigured == false)
- {
- optionsBuilder.UseNpgsql(@"
- Host=localhost;
- Port=5432;
- Database=AdressDirectory;
- Username=postgres;
- Password=postgres");
- }
-
- base.OnConfiguring(optionsBuilder);
- }
-
public DbSet Regions { get; set; }
public DbSet Cities { get; set; }
public DbSet Streets { get; set; }
- protected override void OnModelCreating(ModelBuilder modelBuilder)
+
+ public RepositoryDbContext(DbContextOptions options)
+ : base(options)
{
- modelBuilder.ApplyConfigurationsFromAssembly(typeof(RepositoryDbContext).Assembly);
}
}
}
diff --git a/Address Directory/Web/Program.cs b/Address Directory/Web/Program.cs
index 2d3e8f0..a3e59a3 100644
--- a/Address Directory/Web/Program.cs
+++ b/Address Directory/Web/Program.cs
@@ -7,15 +7,19 @@ using Services.Abstractions;
using Services.Profiles;
var builder = WebApplication.CreateBuilder(args);
-var connectionString = builder.Configuration.GetConnectionString("Database");
+var configuration = builder.Configuration;
+
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
-builder.Services.AddDbContextPool(options =>
-{
- options.UseNpgsql(connectionString);
-});
+
+builder.Services.AddDbContext(
+ options =>
+ {
+ options.UseNpgsql(configuration.GetConnectionString(nameof(RepositoryDbContext)));
+ });
+
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
diff --git a/Address Directory/Web/Properties/launchSettings.json b/Address Directory/Web/Properties/launchSettings.json
index 7f73711..7af4348 100644
--- a/Address Directory/Web/Properties/launchSettings.json
+++ b/Address Directory/Web/Properties/launchSettings.json
@@ -13,6 +13,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
+ "launchUrl": "swagger",
"applicationUrl": "http://localhost:5044",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
@@ -21,6 +22,7 @@
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
+ "launchUrl": "swagger",
"launchBrowser": true,
"applicationUrl": "https://localhost:7184;http://localhost:5044",
"environmentVariables": {
@@ -30,6 +32,7 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
+ "launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
diff --git a/Address Directory/Web/appsettings.Development.json b/Address Directory/Web/appsettings.Development.json
index 770d3e9..7acedde 100644
--- a/Address Directory/Web/appsettings.Development.json
+++ b/Address Directory/Web/appsettings.Development.json
@@ -5,5 +5,8 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
+ },
+ "ConnectionStrings": {
+ "RepositoryDbContext":"Host=localhost;Port=5432;Database=AdressDb;Username=postgres;Password=postgres"
}
}