вынесла в конфиг

This commit is contained in:
VictoriaPresnyakova 2023-05-04 21:53:02 +04:00
parent f709d8cd0e
commit 3aa11ac2dc
7 changed files with 21 additions and 1 deletions

View File

@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TransportGuideContracts\TransportGuideContracts.csproj" />
</ItemGroup>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="connectToDb" value="Host=192.168.56.101;Port=5432;Database=TransportSubd;Username=postgres;Password=1502"/>
</appSettings>
</configuration>

View File

@ -14,6 +14,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TransportGuideDataModels\TransportGuideDataModels.csproj" />
</ItemGroup>

View File

@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
</ItemGroup>
</Project>

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,12 +12,14 @@ namespace TransportGuideDatabaseImplements
{
public class TransportGuideDB : DbContext
{
string dbName = ConfigurationManager.AppSettings["connectToDb"];
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql("Host=192.168.56.101;Port=5432;Database=TransportSubd;Username=postgres;Password=1502");
optionsBuilder.UseNpgsql(dbName);
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -13,6 +13,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
</ItemGroup>
<ItemGroup>