Changed models, added Application layer models

This commit is contained in:
2024-08-15 14:54:23 +03:00
parent 1d8405b4ec
commit c1a4acf414
50 changed files with 628 additions and 647 deletions

View File

@@ -1,4 +1,5 @@
using Domains.ApplicantDomain; using ApplicationLayer.VisaApplication.Models;
using Domains.ApplicantDomain;
using Domains.VisaApplicationDomain; using Domains.VisaApplicationDomain;
namespace ApplicationLayer.VisaApplication; namespace ApplicationLayer.VisaApplication;
@@ -19,7 +20,7 @@ public record CreateVisaApplicationRequest(
bool IsNonResident, bool IsNonResident,
ReentryPermit ReentryPermit, ReentryPermit ReentryPermit,
string JobTitle, string JobTitle,
PlaceOfWork PlaceOfWork, PlaceOfWorkModel PlaceOfWork,
string DestinationCountry, string DestinationCountry,
VisaCategory VisaCategory, VisaCategory VisaCategory,
bool IsForGroup, bool IsForGroup,
@@ -28,4 +29,4 @@ public record CreateVisaApplicationRequest(
PastVisa[] PastVisas, PastVisa[] PastVisas,
PermissionToDestCountry? PermissionToDestCountry, PermissionToDestCountry? PermissionToDestCountry,
PastVisit[] PastVisits PastVisit[] PastVisits
); );

View File

@@ -0,0 +1,16 @@
namespace ApplicationLayer.VisaApplication.Models;
public class AddressModel
{
/// Country part of address
public string Country { get; set; } = null!;
/// City part of address
public string City { get; set; } = null!;
/// Street part of address
public string Street { get; set; } = null!;
/// Building part of address
public string Building { get; set; } = null!;
}

View File

@@ -0,0 +1,13 @@
namespace ApplicationLayer.VisaApplication.Models;
public class PlaceOfWorkModel
{
/// Name of hirer
public string Name { get; set; } = null!;
/// <see cref="AddressModel"/> of hirer
public AddressModel Address { get; set; } = null!;
/// Phone number of hirer
public string PhoneNum { get; set; } = null!;
}

View File

@@ -1,21 +1,20 @@
using Domains.LocationDomain; using Domains.LocationDomain;
namespace Domains.ApplicantDomain namespace Domains.ApplicantDomain;
/// Model of address
/// <remarks>Owned</remarks>
public class Address
{ {
/// Model of address /// Country part of address
/// <remarks>Owned</remarks> public Country Country { get; set; } = null!;
public class Address
{
/// Country part of address
public Country Country { get; set; } = null!;
/// City part of address /// City part of address
public City City { get; set; } = null!; public City City { get; set; } = null!;
/// Street part of address /// Street part of address
public string Street { get; set; } = null!; public string Street { get; set; } = null!;
/// Building part of address /// Building part of address
public string Building { get; set; } = null!; public string Building { get; set; } = null!;
} }
}

View File

@@ -1,57 +1,56 @@
using Domains.LocationDomain; using Domains.LocationDomain;
using Domains.VisaApplicationDomain; using Domains.VisaApplicationDomain;
namespace Domains.ApplicantDomain namespace Domains.ApplicantDomain;
/// Model of an applicant
public class Applicant : IEntity
{ {
/// Model of an applicant /// Unique identifier of the <see cref="Applicant"/>
public class Applicant : IEntity public Guid Id { get; set; }
{
/// Unique identifier of the <see cref="Applicant"/>
public Guid Id { get; set; }
/// Full name of the <see cref="Applicant"/> /// Full name of the <see cref="Applicant"/>
public Name Name { get; set; } = null!; public Name Name { get; set; } = null!;
/// Passport of <see cref="Applicant"/> /// Passport of <see cref="Applicant"/>
public Passport Passport { get; set; } = null!; public Passport Passport { get; set; } = null!;
/// Date of birth of the <see cref="Applicant"/> /// Date of birth of the <see cref="Applicant"/>
public DateTime BirthDate { get; set; } public DateTime BirthDate { get; set; }
/// <see cref="Country"/> of birth of the <see cref="Applicant"/> /// <see cref="Country"/> of birth of the <see cref="Applicant"/>
public Country CountryOfBirth { get; set; } = null!; public Country CountryOfBirth { get; set; } = null!;
/// <see cref="City"/> of birth of the <see cref="Applicant"/> /// <see cref="City"/> of birth of the <see cref="Applicant"/>
public City CityOfBirth { get; set; } = null!; public City CityOfBirth { get; set; } = null!;
/// Citizenship of <see cref="Applicant"/> /// Citizenship of <see cref="Applicant"/>
public string Citizenship { get; set; } = null!; public string Citizenship { get; set; } = null!;
/// Citizenship by birth of <see cref="Applicant"/> /// Citizenship by birth of <see cref="Applicant"/>
public string CitizenshipByBirth { get; set; } = null!; public string CitizenshipByBirth { get; set; } = null!;
/// Gender of <see cref="Applicant"/> /// Gender of <see cref="Applicant"/>
public Gender Gender { get; set; } public Gender Gender { get; set; }
/// Marital status of <see cref="Applicant"/> /// Marital status of <see cref="Applicant"/>
public MaritalStatus MaritalStatus { get; set; } public MaritalStatus MaritalStatus { get; set; }
/// Full name of the <see cref="Applicant"/>'s father /// Full name of the <see cref="Applicant"/>'s father
public Name FatherName { get; set; } = null!; public Name FatherName { get; set; } = null!;
/// Full name of the <see cref="Applicant"/>'s mother /// Full name of the <see cref="Applicant"/>'s mother
public Name MotherName { get; set; } = null!; public Name MotherName { get; set; } = null!;
/// Position of <see cref="Applicant"/> /// Position of <see cref="Applicant"/>
public string JobTitle { get; set; } = null!; public string JobTitle { get; set; } = null!;
/// Place of <see cref="Applicant"/>'s work /// Place of <see cref="Applicant"/>'s work
public PlaceOfWork PlaceOfWork { get; set; } = null!; public PlaceOfWork PlaceOfWork { get; set; } = null!;
/// Is <see cref="Applicant"/> a non-resident /// Is <see cref="Applicant"/> a non-resident
public bool IsNonResident { get; set; } public bool IsNonResident { get; set; }
/// List of <see cref="Applicant"/>'s applications /// List of <see cref="Applicant"/>'s applications
public List<VisaApplication> VisaApplications { get; set; } = null!; public List<VisaApplication> VisaApplications { get; set; } = null!;
} }
}

View File

@@ -1,10 +1,9 @@
namespace Domains.ApplicantDomain namespace Domains.ApplicantDomain;
public enum Gender
{ {
public enum Gender Unknown,
{ Male,
Unknown, Female,
Male, Turkish
Female, }
Turkish
}
}

View File

@@ -1,11 +1,10 @@
namespace Domains.ApplicantDomain namespace Domains.ApplicantDomain;
public enum MaritalStatus
{ {
public enum MaritalStatus Other,
{ Married,
Other, Unmarried,
Married, Separated,
Unmarried, WidowOrWidower
Separated, }
WidowOrWidower
}
}

View File

@@ -1,13 +1,12 @@
namespace Domains.ApplicantDomain namespace Domains.ApplicantDomain;
/// Model of full name
/// <remarks>Owned</remarks>
public class Name
{ {
/// Model of full name public string FirstName { get; set; } = null!;
/// <remarks>Owned</remarks>
public class Name
{
public string FirstName { get; set; } = null!;
public string Surname { get; set; } = null!; public string Surname { get; set; } = null!;
public string? Patronymic { get; set; } public string? Patronymic { get; set; }
} }
}

View File

@@ -1,19 +1,18 @@
namespace Domains.ApplicantDomain namespace Domains.ApplicantDomain;
/// Model of passport
/// <remarks>Owned</remarks>
public class Passport
{ {
/// Model of passport /// Number of <see cref="Passport"/>
/// <remarks>Owned</remarks> public string Number { get; set; } = null!;
public class Passport
{
/// Number of <see cref="Passport"/>
public string Number { get; set; } = null!;
/// Issuing authority of <see cref="Passport"/> /// Issuing authority of <see cref="Passport"/>
public string Issuer { get; set; } = null!; public string Issuer { get; set; } = null!;
/// Date of issue /// Date of issue
public DateTime IssueDate { get; set; } public DateTime IssueDate { get; set; }
/// Date when the <see cref="Passport"/> expires /// Date when the <see cref="Passport"/> expires
public DateTime ExpirationDate { get; set; } public DateTime ExpirationDate { get; set; }
} }
}

View File

@@ -1,17 +1,16 @@
namespace Domains.ApplicantDomain namespace Domains.ApplicantDomain;
public class PlaceOfWork : IEntity
{ {
public class PlaceOfWork : IEntity /// Unique identifier of <see cref="PlaceOfWork"/>
{ public Guid Id { get; private set; } = Guid.NewGuid();
/// Unique identifier of <see cref="PlaceOfWork"/>
public Guid Id { get; private set; } = Guid.NewGuid();
/// Name of hirer /// Name of hirer
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
/// <see cref="ApplicantDomain.Address"/> of hirer /// <see cref="ApplicantDomain.Address"/> of hirer
public Address Address { get; set; } = null!; public Address Address { get; set; } = null!;
/// Phone number of hirer /// Phone number of hirer
public string PhoneNum { get; set; } = null!; public string PhoneNum { get; set; } = null!;
} }
}

View File

@@ -1,8 +1,7 @@
namespace Domains namespace Domains;
/// Interface that every entity should inherit from
public interface IEntity
{ {
/// Interface that every entity should inherit from public Guid Id { get; }
public interface IEntity }
{
public Guid Id { get; }
}
}

View File

@@ -1,15 +1,14 @@
namespace Domains.LocationDomain namespace Domains.LocationDomain;
/// Model of a city
public class City : IEntity
{ {
/// Model of a city /// Unique identifier of the <see cref="City"/>
public class City : IEntity public Guid Id { get; private set; } = Guid.NewGuid();
{
/// Unique identifier of the <see cref="City"/>
public Guid Id { get; private set; } = Guid.NewGuid();
/// Name of the city /// Name of the city
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
/// <see cref="LocationDomain.Country"/> in which the city is located /// <see cref="LocationDomain.Country"/> in which the city is located
public Country Country { get; set; } = null!; public Country Country { get; set; } = null!;
} }
}

View File

@@ -1,18 +1,17 @@
namespace Domains.LocationDomain namespace Domains.LocationDomain;
/// Model of a country
public class Country : IEntity
{ {
/// Model of a country /// Unique identifier of the <see cref="Country"/>
public class Country : IEntity public Guid Id { get; private set; } = Guid.NewGuid();
{
/// Unique identifier of the <see cref="Country"/>
public Guid Id { get; private set; } = Guid.NewGuid();
/// Name of the country /// Name of the country
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
/// Located in Schengen area /// Located in Schengen area
public bool IsSchengen { get; set; } public bool IsSchengen { get; set; }
/// List of <see cref="City"/> that country have /// List of <see cref="City"/> that country have
public List<City> Cities { get; set; } = null!; public List<City> Cities { get; set; } = null!;
} }
}

View File

@@ -1,20 +1,17 @@
using Domains.ApplicantDomain; using Domains.ApplicantDomain;
namespace Domains.VisaApplicationDomain namespace Domains.VisaApplicationDomain;
/// Visa that <see cref="Applicant"/> already had
/// <remarks>Owned</remarks>
public class PastVisa
{ {
/// Visa that <see cref="Applicant"/> already had /// Date of issue
public class PastVisa : IEntity public DateTime IssueDate { get; set; }
{
/// Unique identifier of <see cref="PastVisa"/>
public Guid Id { get; private set; } = Guid.NewGuid();
/// Date of issue /// Name of visa
public DateTime IssueDate { get; set; } public string Name { get; set; } = null!;
/// Name of visa /// Date when visa expires
public string Name { get; set; } = null!; public DateTime ExpirationDate { get; set; }
/// Date when visa expires
public DateTime ExpirationDate { get; set; }
}
} }

View File

@@ -1,17 +1,14 @@
using Domains.ApplicantDomain; using Domains.ApplicantDomain;
namespace Domains.VisaApplicationDomain namespace Domains.VisaApplicationDomain;
/// Visit in a Schengen country that <see cref="Applicant"/> already had
/// <remarks>Owned</remarks>
public class PastVisit
{ {
/// Visit in a Schengen country that <see cref="Applicant"/> already had /// First day of <see cref="PastVisit"/>
public class PastVisit : IEntity public DateTime StartDate { get; set; }
{
/// Unique identifier of <see cref="PastVisit"/>
public Guid Id { get; private set; } = Guid.NewGuid();
/// First day of <see cref="PastVisit"/> /// Last day of <see cref="PastVisit"/>
public DateTime StartDate { get; set; } public DateTime EndDate { get; set; }
/// Last day of <see cref="PastVisit"/>
public DateTime EndDate { get; set; }
}
} }

View File

@@ -1,13 +1,12 @@
namespace Domains.VisaApplicationDomain namespace Domains.VisaApplicationDomain;
{
/// Permission to enter the destination country
/// <remarks>Owned</remarks>
public class PermissionToDestCountry
{
/// Date when <see cref="PermissionToDestCountry"/> expires
public DateTime ExpirationDate { get; set; }
/// Issuing authority /// Permission to enter the destination country
public string Issuer { get; set; } = null!; /// <remarks>Owned</remarks>
} public class PermissionToDestCountry
} {
/// Date when <see cref="PermissionToDestCountry"/> expires
public DateTime ExpirationDate { get; set; }
/// Issuing authority
public string Issuer { get; set; } = null!;
}

View File

@@ -1,13 +1,12 @@
namespace Domains.VisaApplicationDomain namespace Domains.VisaApplicationDomain;
{
/// Permission to enter a country the issuer wants to come from
/// <remarks>Owned</remarks>
public class ReentryPermit
{
/// Number of <see cref="ReentryPermit"/>
public string Number { get; set; } = null!;
/// Date when <see cref="ReentryPermit"/> expires /// Permission to enter a country the issuer wants to come from
public DateTime ExpirationDate { get; set; } /// <remarks>Owned</remarks>
} public class ReentryPermit
} {
/// Number of <see cref="ReentryPermit"/>
public string Number { get; set; } = null!;
/// Date when <see cref="ReentryPermit"/> expires
public DateTime ExpirationDate { get; set; }
}

View File

@@ -1,10 +1,9 @@
namespace Domains.VisaApplicationDomain namespace Domains.VisaApplicationDomain;
/// Requested number of entries
public enum RequestedNumberOfEntries
{ {
/// Requested number of entries Many,
public enum RequestedNumberOfEntries One,
{ Two
Many, }
One,
Two
}
}

View File

@@ -1,51 +1,50 @@
using Domains.ApplicantDomain; using Domains.ApplicantDomain;
using Domains.LocationDomain; using Domains.LocationDomain;
namespace Domains.VisaApplicationDomain namespace Domains.VisaApplicationDomain;
/// Model of visit request
public class VisaApplication : IEntity
{ {
/// Model of visit request /// Unique identifier of <see cref="VisaApplication"/>
public class VisaApplication : IEntity public Guid Id { get; private set; } = Guid.NewGuid();
{
/// Unique identifier of <see cref="VisaApplication"/>
public Guid Id { get; private set; } = Guid.NewGuid();
/// Identifier of the <see cref="Applicant"/> /// Identifier of the <see cref="Applicant"/>
public Guid ApplicantId { get; set; } public Guid ApplicantId { get; set; }
/// Applicant of <see cref="VisaApplication"/> /// Applicant of <see cref="VisaApplication"/>
public Applicant Applicant { get; set; } = null!; public Applicant Applicant { get; set; } = null!;
/// <inheritdoc cref="Domains.VisaApplicationDomain.ReentryPermit"/> /// <inheritdoc cref="Domains.VisaApplicationDomain.ReentryPermit"/>
/// <remarks>always null if <see cref="Applicant"/> is not a non-resident</remarks> /// <remarks>always null if <see cref="Applicant"/> is not a non-resident</remarks>
public ReentryPermit? ReentryPermit { get; set; } public ReentryPermit? ReentryPermit { get; set; }
/// <see cref="Country"/> that <see cref="Applicant"/> wants to visit /// <see cref="Country"/> that <see cref="Applicant"/> wants to visit
public Country DestinationCountry { get; set; } = null!; public Country DestinationCountry { get; set; } = null!;
/// <summary> /// <summary>
/// List of <see cref="PastVisa"/> that applicant had before /// List of <see cref="PastVisa"/> that applicant had before
/// </summary> /// </summary>
public List<PastVisa> PastVisas { get; set; } = null!; public List<PastVisa> PastVisas { get; set; } = null!;
/// Permission to enter the destination country of <see cref="Applicant"/> /// Permission to enter the destination country of <see cref="Applicant"/>
/// <remarks>always null if <see cref="DestinationCountry"/> is Schengen</remarks> /// <remarks>always null if <see cref="DestinationCountry"/> is Schengen</remarks>
public PermissionToDestCountry? PermissionToDestCountry { get; set; } public PermissionToDestCountry? PermissionToDestCountry { get; set; }
public List<PastVisit> PastVisits { get; set; } = null!; public List<PastVisit> PastVisits { get; set; } = null!;
/// <see cref="Domains.VisaApplicationDomain.VisaCategory"/> /// <see cref="Domains.VisaApplicationDomain.VisaCategory"/>
public VisaCategory VisaCategory { get; set; } public VisaCategory VisaCategory { get; set; }
/// Is for group /// Is for group
public bool ForGroup { get; set; } public bool ForGroup { get; set; }
/// <see cref="Domains.VisaApplicationDomain.RequestedNumberOfEntries"/> /// <see cref="Domains.VisaApplicationDomain.RequestedNumberOfEntries"/>
public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; }
/// When application was created /// When application was created
public DateTime RequestDate { get; set; } public DateTime RequestDate { get; set; }
/// Valid days requested /// Valid days requested
public int ValidDaysRequested { get; set; } public int ValidDaysRequested { get; set; }
} }
}

View File

@@ -1,9 +1,8 @@
namespace Domains.VisaApplicationDomain namespace Domains.VisaApplicationDomain;
/// Category of visa
public enum VisaCategory
{ {
/// Category of visa Transit,
public enum VisaCategory ShortDated
{ }
Transit,
ShortDated
}
}

View File

@@ -2,18 +2,17 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration namespace Infrastructure.Database.Applicants.Configuration;
public class AddressConfiguration : IEntityTypeConfiguration<Address>
{ {
public class AddressConfiguration : IEntityTypeConfiguration<Address> public void Configure(EntityTypeBuilder<Address> entity)
{ {
public void Configure(EntityTypeBuilder<Address> entity) entity.Property(p => p.Street)
{ .IsUnicode(false)
entity.Property(p => p.Street) .HasMaxLength(100);
.IsUnicode(false) entity.Property(p => p.Building)
.HasMaxLength(100); .IsUnicode(false)
entity.Property(p => p.Building) .HasMaxLength(10);
.IsUnicode(false)
.HasMaxLength(10);
}
} }
} }

View File

@@ -2,26 +2,25 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration namespace Infrastructure.Database.Applicants.Configuration;
public class ApplicantConfiguration : IEntityTypeConfiguration<Applicant>
{ {
public class ApplicantConfiguration : IEntityTypeConfiguration<Applicant> public void Configure(EntityTypeBuilder<Applicant> entity)
{ {
public void Configure(EntityTypeBuilder<Applicant> entity) entity.ToTable("Applicants");
{
entity.ToTable("Applicants");
entity.OwnsOne(p => p.Name); entity.OwnsOne(p => p.Name);
entity.OwnsOne(p => p.FatherName); entity.OwnsOne(p => p.FatherName);
entity.OwnsOne(p => p.MotherName); entity.OwnsOne(p => p.MotherName);
entity.OwnsOne(p => p.Passport); entity.OwnsOne(p => p.Passport);
entity.Property(p => p.Citizenship) entity.Property(p => p.Citizenship)
.IsUnicode(false) .IsUnicode(false)
.HasMaxLength(30); .HasMaxLength(30);
entity.Property(p => p.CitizenshipByBirth) entity.Property(p => p.CitizenshipByBirth)
.IsUnicode(false) .IsUnicode(false)
.HasMaxLength(30); .HasMaxLength(30);
}
} }
} }

View File

@@ -2,23 +2,22 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration namespace Infrastructure.Database.Applicants.Configuration;
public class NameConfiguration : IEntityTypeConfiguration<Name>
{ {
public class NameConfiguration : IEntityTypeConfiguration<Name> public void Configure(EntityTypeBuilder<Name> entity)
{ {
public void Configure(EntityTypeBuilder<Name> entity) entity.Property(p => p.FirstName)
{ .IsUnicode(false)
entity.Property(p => p.FirstName) .HasMaxLength(50);
.IsUnicode(false)
.HasMaxLength(50);
entity.Property(p => p.Surname) entity.Property(p => p.Surname)
.IsUnicode(false) .IsUnicode(false)
.HasMaxLength(50); .HasMaxLength(50);
entity.Property(p => p.Patronymic) entity.Property(p => p.Patronymic)
.IsUnicode(false) .IsUnicode(false)
.HasMaxLength(50); .HasMaxLength(50);
}
} }
} }

View File

@@ -2,19 +2,18 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration namespace Infrastructure.Database.Applicants.Configuration;
{
public class PassportConfiguration : IEntityTypeConfiguration<Passport>
{
public void Configure(EntityTypeBuilder<Passport> entity)
{
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(20);
entity.Property(p => p.Issuer) public class PassportConfiguration : IEntityTypeConfiguration<Passport>
.IsUnicode(false) {
.HasMaxLength(200); public void Configure(EntityTypeBuilder<Passport> entity)
} {
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(20);
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
} }
} }

View File

@@ -2,21 +2,20 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration namespace Infrastructure.Database.Applicants.Configuration;
public class PlaceOfWorkConfiguration : IEntityTypeConfiguration<PlaceOfWork>
{ {
public class PlaceOfWorkConfiguration : IEntityTypeConfiguration<PlaceOfWork> public void Configure(EntityTypeBuilder<PlaceOfWork> entity)
{ {
public void Configure(EntityTypeBuilder<PlaceOfWork> entity) entity.OwnsOne(p => p.Address);
{
entity.OwnsOne(p => p.Address);
entity.Property(p => p.Name) entity.Property(p => p.Name)
.IsUnicode(false) .IsUnicode(false)
.HasMaxLength(200); .HasMaxLength(200);
entity.Property(p => p.PhoneNum) entity.Property(p => p.PhoneNum)
.IsUnicode(false) .IsUnicode(false)
.HasMaxLength(20); .HasMaxLength(20);
}
} }
} }

View File

@@ -2,21 +2,20 @@
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Applicants.Repositories namespace Infrastructure.Database.Applicants.Repositories;
/// Repository pattern for <see cref="Applicant"/>
/// <param name="reader"><inheritdoc cref="IGenericReader"/></param>
/// <param name="writer"><inheritdoc cref="IGenericWriter"/></param>
/// <param name="unitOfWork"><inheritdoc cref="IUnitOfWork"/></param>
public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<Applicant>(reader, writer, unitOfWork), IApplicantsRepository
{ {
/// Repository pattern for <see cref="Applicant"/> protected override IQueryable<Applicant> LoadDomain()
/// <param name="reader"><inheritdoc cref="IGenericReader"/></param>
/// <param name="writer"><inheritdoc cref="IGenericWriter"/></param>
/// <param name="unitOfWork"><inheritdoc cref="IUnitOfWork"/></param>
public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<Applicant>(reader, writer, unitOfWork), IApplicantsRepository
{ {
protected override IQueryable<Applicant> LoadDomain() return base.LoadDomain()
{ .Include(a => a.CountryOfBirth)
return base.LoadDomain() .Include(a => a.CityOfBirth)
.Include(a => a.CountryOfBirth) .Include(a => a.PlaceOfWork);
.Include(a => a.CityOfBirth)
.Include(a => a.PlaceOfWork);
}
} }
} }

View File

@@ -1,8 +1,7 @@
using Domains.ApplicantDomain; using Domains.ApplicantDomain;
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
namespace Infrastructure.Database.Applicants.Repositories namespace Infrastructure.Database.Applicants.Repositories;
{
/// Repository pattern for <see cref="Applicant"/> /// Repository pattern for <see cref="Applicant"/>
public interface IApplicantsRepository : IGenericRepository<Applicant> { } public interface IApplicantsRepository : IGenericRepository<Applicant> { }
}

View File

@@ -2,39 +2,38 @@
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database namespace Infrastructure.Database;
public class DbContext(DbContextOptions<DbContext> opts)
: Microsoft.EntityFrameworkCore.DbContext(opts), IGenericWriter, IGenericReader, IUnitOfWork
{ {
public class DbContext(DbContextOptions<DbContext> opts) protected override void OnModelCreating(ModelBuilder modelBuilder)
: Microsoft.EntityFrameworkCore.DbContext(opts), IGenericWriter, IGenericReader, IUnitOfWork
{ {
protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
{
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
async Task IGenericWriter.AddAsync<T>(T entity, CancellationToken cancellationToken)
{
await AddAsync(entity, cancellationToken);
}
void IGenericWriter.Update<T>(T entity)
{
Update(entity);
}
void IGenericWriter.Remove<T>(T entity)
{
Remove(entity);
}
IQueryable<T> IGenericReader.GetAll<T>()
{
return Set<T>();
}
async Task IUnitOfWork.SaveAsync(CancellationToken cancellationToken)
{
await SaveChangesAsync(cancellationToken);
}
} }
}
async Task IGenericWriter.AddAsync<T>(T entity, CancellationToken cancellationToken)
{
await AddAsync(entity, cancellationToken);
}
void IGenericWriter.Update<T>(T entity)
{
Update(entity);
}
void IGenericWriter.Remove<T>(T entity)
{
Remove(entity);
}
IQueryable<T> IGenericReader.GetAll<T>()
{
return Set<T>();
}
async Task IUnitOfWork.SaveAsync(CancellationToken cancellationToken)
{
await SaveChangesAsync(cancellationToken);
}
}

View File

@@ -1,10 +1,9 @@
using Domains; using Domains;
namespace Infrastructure.Database.GeneralExceptions namespace Infrastructure.Database.GeneralExceptions;
{
/// Exception to throw when entity with specific id not found /// Exception to throw when entity with specific id not found
/// <param name="id">Identifier of entity</param> /// <param name="id">Identifier of entity</param>
/// <typeparam name="T">Not found entity type</typeparam> /// <typeparam name="T">Not found entity type</typeparam>
public class EntityNotFoundException<T>(Guid id) : Exception($"Entity {typeof(T).Name} with id '{id}' not found") public class EntityNotFoundException<T>(Guid id) : Exception($"Entity {typeof(T).Name} with id '{id}' not found")
where T : class, IEntity; where T : class, IEntity;
}

View File

@@ -2,52 +2,51 @@
using Infrastructure.Database.GeneralExceptions; using Infrastructure.Database.GeneralExceptions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Generic namespace Infrastructure.Database.Generic;
/// Generic repository pattern
/// <param name="writer"><inheritdoc cref="IGenericWriter"/></param>
/// <param name="unitOfWork"><inheritdoc cref="IUnitOfWork"/></param>
/// <typeparam name="T">Type of entity</typeparam>
/// <remarks>Should be inherited to create typed repositories</remarks>
public abstract class GenericRepository<T>(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) : IGenericRepository<T>
where T : class, IEntity
{ {
/// Generic repository pattern /// <inheritdoc cref="IGenericRepository{T}.GetAllAsync"/>
/// <param name="writer"><inheritdoc cref="IGenericWriter"/></param> public async Task<List<T>> GetAllAsync(CancellationToken cancellationToken)
/// <param name="unitOfWork"><inheritdoc cref="IUnitOfWork"/></param> => await LoadDomain().ToListAsync(cancellationToken);
/// <typeparam name="T">Type of entity</typeparam>
/// <remarks>Should be inherited to create typed repositories</remarks> /// <inheritdoc cref="IGenericRepository{T}.GetOneAsync"/>
public abstract class GenericRepository<T>(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) : IGenericRepository<T> public async Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken)
where T : class, IEntity
{ {
/// <inheritdoc cref="IGenericRepository{T}.GetAllAsync"/> var result = await LoadDomain().SingleOrDefaultAsync(a => a.Id == id, cancellationToken);
public async Task<List<T>> GetAllAsync(CancellationToken cancellationToken) return result ?? throw new EntityNotFoundException<T>(id);
=> await LoadDomain().ToListAsync(cancellationToken);
/// <inheritdoc cref="IGenericRepository{T}.GetOneAsync"/>
public async Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken)
{
var result = await LoadDomain().SingleOrDefaultAsync(a => a.Id == id, cancellationToken);
return result ?? throw new EntityNotFoundException<T>(id);
}
/// <inheritdoc cref="IGenericRepository{T}.AddAsync"/>
public async Task AddAsync(T entity, CancellationToken cancellationToken)
=> await writer.AddAsync(entity, cancellationToken);
/// <inheritdoc cref="IGenericRepository{T}.UpdateAsync"/>
public async Task UpdateAsync(T entity, CancellationToken cancellationToken)
{
await GetOneAsync(entity.Id, cancellationToken);
writer.Update(entity);
}
/// <inheritdoc cref="IGenericRepository{T}.Remove"/>
public void Remove(T entity)
{
writer.Remove(entity);
}
/// <inheritdoc cref="IGenericRepository{T}.SaveAsync"/>
public async Task SaveAsync(CancellationToken cancellationToken)
=> await unitOfWork.SaveAsync(cancellationToken);
/// Should be overriden to load navigation properties of entity
protected virtual IQueryable<T> LoadDomain()
{
return reader.GetAll<T>();
}
} }
}
/// <inheritdoc cref="IGenericRepository{T}.AddAsync"/>
public async Task AddAsync(T entity, CancellationToken cancellationToken)
=> await writer.AddAsync(entity, cancellationToken);
/// <inheritdoc cref="IGenericRepository{T}.UpdateAsync"/>
public async Task UpdateAsync(T entity, CancellationToken cancellationToken)
{
await GetOneAsync(entity.Id, cancellationToken);
writer.Update(entity);
}
/// <inheritdoc cref="IGenericRepository{T}.Remove"/>
public void Remove(T entity)
{
writer.Remove(entity);
}
/// <inheritdoc cref="IGenericRepository{T}.SaveAsync"/>
public async Task SaveAsync(CancellationToken cancellationToken)
=> await unitOfWork.SaveAsync(cancellationToken);
/// Should be overriden to load navigation properties of entity
protected virtual IQueryable<T> LoadDomain()
{
return reader.GetAll<T>();
}
}

View File

@@ -1,12 +1,11 @@
using Domains; using Domains;
namespace Infrastructure.Database.Generic namespace Infrastructure.Database.Generic;
/// Reads from data storage
public interface IGenericReader
{ {
/// Reads from data storage /// Get all entities of type T stored in storage
public interface IGenericReader /// <typeparam name="T">Entity type to seek in storage</typeparam>
{ IQueryable<T> GetAll<T>() where T : class, IEntity;
/// Get all entities of type T stored in storage }
/// <typeparam name="T">Entity type to seek in storage</typeparam>
IQueryable<T> GetAll<T>() where T : class, IEntity;
}
}

View File

@@ -1,37 +1,36 @@
using Domains; using Domains;
namespace Infrastructure.Database.Generic namespace Infrastructure.Database.Generic;
/// <summary>
/// Generic repository pattern
/// </summary>
/// <typeparam name="T">Entity type</typeparam>
public interface IGenericRepository<T> where T : class, IEntity
{ {
/// Get all entities from data storage
Task<List<T>> GetAllAsync(CancellationToken cancellationToken);
/// Get one entity with specific id
/// <param name="id">Identifier of entity</param>
Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken);
/// Add entity to storage
/// <param name="entity">Entity to add</param>
Task AddAsync(T entity, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Generic repository pattern /// Update entity in storage
/// </summary> /// </summary>
/// <typeparam name="T">Entity type</typeparam> /// <param name="entity">Entity to update</param>
public interface IGenericRepository<T> where T : class, IEntity Task UpdateAsync(T entity, CancellationToken cancellationToken);
{
/// Get all entities from data storage
Task<List<T>> GetAllAsync(CancellationToken cancellationToken);
/// Get one entity with specific id /// <summary>
/// <param name="id">Identifier of entity</param> /// Remove entity from storage
Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken); /// </summary>
/// <param name="entity">Entity to remove</param>
void Remove(T entity);
/// Add entity to storage /// Save changes in storage
/// <param name="entity">Entity to add</param> Task SaveAsync(CancellationToken cancellationToken);
Task AddAsync(T entity, CancellationToken cancellationToken); }
/// <summary>
/// Update entity in storage
/// </summary>
/// <param name="entity">Entity to update</param>
Task UpdateAsync(T entity, CancellationToken cancellationToken);
/// <summary>
/// Remove entity from storage
/// </summary>
/// <param name="entity">Entity to remove</param>
void Remove(T entity);
/// Save changes in storage
Task SaveAsync(CancellationToken cancellationToken);
}
}

View File

@@ -1,25 +1,24 @@
using Domains; using Domains;
namespace Infrastructure.Database.Generic namespace Infrastructure.Database.Generic;
/// Writes data to data storage
/// <remarks><see cref="IUnitOfWork"/> should be used to save changes</remarks>
public interface IGenericWriter
{ {
/// Writes data to data storage /// Add entity to data storage
/// <remarks><see cref="IUnitOfWork"/> should be used to save changes</remarks> /// <param name="entity">Entity to add</param>
public interface IGenericWriter /// <param name="cancellationToken">Cancellation Token</param>
{ /// <typeparam name="T">Entity type</typeparam>
/// Add entity to data storage Task AddAsync<T>(T entity, CancellationToken cancellationToken) where T : class, IEntity;
/// <param name="entity">Entity to add</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <typeparam name="T">Entity type</typeparam>
Task AddAsync<T>(T entity, CancellationToken cancellationToken) where T : class, IEntity;
/// Update entity in data storage /// Update entity in data storage
/// <param name="entity">Entity to update</param> /// <param name="entity">Entity to update</param>
/// <typeparam name="T">Entity type</typeparam> /// <typeparam name="T">Entity type</typeparam>
void Update<T>(T entity) where T : class, IEntity; void Update<T>(T entity) where T : class, IEntity;
/// Remove entity from data storage /// Remove entity from data storage
/// <param name="entity">Entity to remove</param> /// <param name="entity">Entity to remove</param>
/// <typeparam name="T">Entity type</typeparam> /// <typeparam name="T">Entity type</typeparam>
void Remove<T>(T entity) where T : class, IEntity; void Remove<T>(T entity) where T : class, IEntity;
} }
}

View File

@@ -1,9 +1,8 @@
namespace Infrastructure.Database namespace Infrastructure.Database;
public interface IUnitOfWork
{ {
public interface IUnitOfWork /// Saves changes in data storage
{ /// <param name="cancellationToken">Cancellation Token</param>
/// Saves changes in data storage Task SaveAsync(CancellationToken cancellationToken);
/// <param name="cancellationToken">Cancellation Token</param> }
Task SaveAsync(CancellationToken cancellationToken);
}
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Locations.Configuration namespace Infrastructure.Database.Locations.Configuration;
public class CityConfiguration : IEntityTypeConfiguration<City>
{ {
public class CityConfiguration : IEntityTypeConfiguration<City> public void Configure(EntityTypeBuilder<City> entity)
{ {
public void Configure(EntityTypeBuilder<City> entity) entity.Property(p => p.Name)
{ .IsUnicode(false)
entity.Property(p => p.Name) .HasMaxLength(70);
.IsUnicode(false)
.HasMaxLength(70);
}
} }
} }

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Locations.Configuration namespace Infrastructure.Database.Locations.Configuration;
public class CountryConfiguration : IEntityTypeConfiguration<Country>
{ {
public class CountryConfiguration : IEntityTypeConfiguration<Country> public void Configure(EntityTypeBuilder<Country> entity)
{ {
public void Configure(EntityTypeBuilder<Country> entity) entity.Property(p => p.Name)
{ .IsUnicode(false)
entity.Property(p => p.Name) .HasMaxLength(70);
.IsUnicode(false)
.HasMaxLength(70);
}
} }
} }

View File

@@ -2,14 +2,13 @@
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Locations.Repositories.Cities namespace Infrastructure.Database.Locations.Repositories.Cities;
public sealed class CitiesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<City>(reader, writer, unitOfWork), ICitiesRepository
{ {
public sealed class CitiesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) protected override IQueryable<City> LoadDomain()
: GenericRepository<City>(reader, writer, unitOfWork), ICitiesRepository
{ {
protected override IQueryable<City> LoadDomain() return base.LoadDomain().Include(c => c.Country);
{
return base.LoadDomain().Include(c => c.Country);
}
} }
} }

View File

@@ -1,7 +1,6 @@
using Domains.LocationDomain; using Domains.LocationDomain;
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
namespace Infrastructure.Database.Locations.Repositories.Cities namespace Infrastructure.Database.Locations.Repositories.Cities;
{
public interface ICitiesRepository : IGenericRepository<City> { } public interface ICitiesRepository : IGenericRepository<City> { }
}

View File

@@ -2,14 +2,13 @@
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Locations.Repositories.Countries namespace Infrastructure.Database.Locations.Repositories.Countries;
public sealed class CountriesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<Country>(reader, writer, unitOfWork), ICountriesRepository
{ {
public sealed class CountriesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) protected override IQueryable<Country> LoadDomain()
: GenericRepository<Country>(reader, writer, unitOfWork), ICountriesRepository
{ {
protected override IQueryable<Country> LoadDomain() return base.LoadDomain().Include(c => c.Cities);
{
return base.LoadDomain().Include(c => c.Cities);
}
} }
} }

View File

@@ -1,7 +1,6 @@
using Domains.LocationDomain; using Domains.LocationDomain;
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
namespace Infrastructure.Database.Locations.Repositories.Countries namespace Infrastructure.Database.Locations.Repositories.Countries;
{
public interface ICountriesRepository : IGenericRepository<Country> { } public interface ICountriesRepository : IGenericRepository<Country> { }
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration namespace Infrastructure.Database.VisaApplications.Configuration;
public class PastVisaConfiguration : IEntityTypeConfiguration<PastVisa>
{ {
public class PastVisaConfiguration : IEntityTypeConfiguration<PastVisa> public void Configure(EntityTypeBuilder<PastVisa> entity)
{ {
public void Configure(EntityTypeBuilder<PastVisa> entity) entity.Property(p => p.Name)
{ .IsUnicode(false)
entity.Property(p => p.Name) .HasMaxLength(70);
.IsUnicode(false)
.HasMaxLength(70);
}
} }
} }

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration namespace Infrastructure.Database.VisaApplications.Configuration;
public class PermissionToDestCountryConfiguration : IEntityTypeConfiguration<PermissionToDestCountry>
{ {
public class PermissionToDestCountryConfiguration : IEntityTypeConfiguration<PermissionToDestCountry> public void Configure(EntityTypeBuilder<PermissionToDestCountry> entity)
{ {
public void Configure(EntityTypeBuilder<PermissionToDestCountry> entity) entity.Property(p => p.Issuer)
{ .IsUnicode(false)
entity.Property(p => p.Issuer) .HasMaxLength(200);
.IsUnicode(false)
.HasMaxLength(200);
}
} }
} }

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration namespace Infrastructure.Database.VisaApplications.Configuration;
public class ReentryPermitConfiguration : IEntityTypeConfiguration<ReentryPermit>
{ {
public class ReentryPermitConfiguration : IEntityTypeConfiguration<ReentryPermit> public void Configure(EntityTypeBuilder<ReentryPermit> entity)
{ {
public void Configure(EntityTypeBuilder<ReentryPermit> entity) entity.Property(p => p.Number)
{ .IsUnicode(false)
entity.Property(p => p.Number) .HasMaxLength(25);
.IsUnicode(false)
.HasMaxLength(25);
}
} }
} }

View File

@@ -2,21 +2,22 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration namespace Infrastructure.Database.VisaApplications.Configuration;
public class VisaApplicationConfiguration : IEntityTypeConfiguration<VisaApplication>
{ {
public class VisaApplicationConfiguration : IEntityTypeConfiguration<VisaApplication> public void Configure(EntityTypeBuilder<VisaApplication> entity)
{ {
public void Configure(EntityTypeBuilder<VisaApplication> entity) entity.ToTable("VisaApplications");
{
entity.ToTable("VisaApplications");
entity.HasOne(va => va.Applicant) entity.HasOne(va => va.Applicant)
.WithMany(a => a.VisaApplications) .WithMany(a => a.VisaApplications)
.HasForeignKey(va => va.ApplicantId) .HasForeignKey(va => va.ApplicantId)
.IsRequired(); .IsRequired();
entity.OwnsOne(p => p.ReentryPermit); entity.OwnsOne(p => p.ReentryPermit);
entity.OwnsOne(p => p.PermissionToDestCountry); entity.OwnsOne(p => p.PermissionToDestCountry);
} entity.OwnsMany(p => p.PastVisits).ToTable("PastVisits");
entity.OwnsMany(p => p.PastVisas).ToTable("PastVisas");
} }
} }

View File

@@ -1,7 +1,6 @@
using Domains.VisaApplicationDomain; using Domains.VisaApplicationDomain;
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
namespace Infrastructure.Database.VisaApplications.Repositories namespace Infrastructure.Database.VisaApplications.Repositories;
{
public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> { } public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> { }
}

View File

@@ -2,17 +2,16 @@
using Infrastructure.Database.Generic; using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.VisaApplications.Repositories namespace Infrastructure.Database.VisaApplications.Repositories;
public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork)
: GenericRepository<VisaApplication>(reader, writer, unitOfWork), IVisaApplicationsRepository
{ {
public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) protected override IQueryable<VisaApplication> LoadDomain()
: GenericRepository<VisaApplication>(reader, writer, unitOfWork), IVisaApplicationsRepository
{ {
protected override IQueryable<VisaApplication> LoadDomain() return base.LoadDomain()
{ .Include(a => a.DestinationCountry)
return base.LoadDomain() .Include(a => a.PastVisas)
.Include(a => a.DestinationCountry) .Include(a => a.PastVisits);
.Include(a => a.PastVisas)
.Include(a => a.PastVisits);
}
} }
} }

View File

@@ -8,28 +8,27 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using DbContext = Infrastructure.Database.DbContext; using DbContext = Infrastructure.Database.DbContext;
namespace Infrastructure namespace Infrastructure;
/// Provides methods to add services to DI-container
public static class DependencyInjection
{ {
/// Provides methods to add services to DI-container /// Add services needed for Infrastructure layer
public static class DependencyInjection public static IServiceCollection AddInfrastructure(this IServiceCollection services)
{ {
/// Add services needed for Infrastructure layer //TODO строка подключения
public static IServiceCollection AddInfrastructure(this IServiceCollection services) services.AddDbContext<DbContext>(opts =>
{ opts.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=visadb;Integrated Security=True;"));
//TODO строка подключения
services.AddDbContext<DbContext>(opts =>
opts.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=visadb;Integrated Security=True;"));
services.AddScoped<IGenericReader>(serviceProvider => serviceProvider.GetRequiredService<DbContext>()); services.AddScoped<IGenericReader>(serviceProvider => serviceProvider.GetRequiredService<DbContext>());
services.AddScoped<IGenericWriter>(serviceProvider => serviceProvider.GetRequiredService<DbContext>()); services.AddScoped<IGenericWriter>(serviceProvider => serviceProvider.GetRequiredService<DbContext>());
services.AddScoped<IUnitOfWork>(serviceProvider => serviceProvider.GetRequiredService<DbContext>()); services.AddScoped<IUnitOfWork>(serviceProvider => serviceProvider.GetRequiredService<DbContext>());
services.AddScoped<IApplicantsRepository, ApplicantsRepository>(); services.AddScoped<IApplicantsRepository, ApplicantsRepository>();
services.AddScoped<IVisaApplicationsRepository, VisaApplicationsRepository>(); services.AddScoped<IVisaApplicationsRepository, VisaApplicationsRepository>();
services.AddScoped<ICitiesRepository, CitiesRepository>(); services.AddScoped<ICitiesRepository, CitiesRepository>();
services.AddScoped<ICountriesRepository, CountriesRepository>(); services.AddScoped<ICountriesRepository, CountriesRepository>();
return services; return services;
}
} }
} }

View File

@@ -1,31 +1,30 @@
using System.Reflection; using System.Reflection;
using Infrastructure; using Infrastructure;
namespace SchengenVisaApi namespace SchengenVisaApi;
/// Provides methods to add services to DI-container
public static class DependencyInjection
{ {
/// Provides methods to add services to DI-container /// Add needed services
public static class DependencyInjection public static IServiceCollection RegisterServices(this IServiceCollection services)
{ {
/// Add needed services services
public static IServiceCollection RegisterServices(this IServiceCollection services) .AddInfrastructure()
{ .AddPresentation();
services
.AddInfrastructure()
.AddPresentation();
return services; return services;
}
/// Add services needed for Presentation layer
private static void AddPresentation(this IServiceCollection services)
{
services.AddControllers();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
}
} }
}
/// Add services needed for Presentation layer
private static void AddPresentation(this IServiceCollection services)
{
services.AddControllers();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
}
}

View File

@@ -1,5 +1,4 @@
namespace SchengenVisaApi; namespace SchengenVisaApi;
#pragma warning disable CS1591 #pragma warning disable CS1591
public class Program public class Program
{ {
@@ -14,4 +13,4 @@ public class Program
app.Run(); app.Run();
} }
} }
#pragma warning restore CS1591 #pragma warning restore CS1591

View File

@@ -1,19 +1,18 @@
namespace SchengenVisaApi namespace SchengenVisaApi;
/// Provides methods for configuring middleware
public static class PipelineRequest
{ {
/// Provides methods for configuring middleware /// Configure middleware
public static class PipelineRequest public static WebApplication ConfigurePipelineRequest(this WebApplication app)
{ {
/// Configure middleware app.UseSwagger()
public static WebApplication ConfigurePipelineRequest(this WebApplication app) .UseSwaggerUI();
{
app.UseSwagger()
.UseSwaggerUI();
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.MapControllers(); app.MapControllers();
return app; return app;
}
} }
} }