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;
namespace ApplicationLayer.VisaApplication;
@@ -19,7 +20,7 @@ public record CreateVisaApplicationRequest(
bool IsNonResident,
ReentryPermit ReentryPermit,
string JobTitle,
PlaceOfWork PlaceOfWork,
PlaceOfWorkModel PlaceOfWork,
string DestinationCountry,
VisaCategory VisaCategory,
bool IsForGroup,
@@ -28,4 +29,4 @@ public record CreateVisaApplicationRequest(
PastVisa[] PastVisas,
PermissionToDestCountry? PermissionToDestCountry,
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;
namespace Domains.ApplicantDomain
namespace Domains.ApplicantDomain;
/// Model of address
/// <remarks>Owned</remarks>
public class Address
{
/// Model of address
/// <remarks>Owned</remarks>
public class Address
{
/// Country part of address
public Country Country { get; set; } = null!;
/// Country part of address
public Country Country { get; set; } = null!;
/// City part of address
public City City { get; set; } = null!;
/// City part of address
public City City { get; set; } = null!;
/// Street part of address
public string Street { get; set; } = null!;
/// Street part of address
public string Street { get; set; } = null!;
/// Building part of address
public string Building { get; set; } = null!;
}
}
/// Building part of address
public string Building { get; set; } = null!;
}

View File

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

View File

@@ -1,11 +1,10 @@
namespace Domains.ApplicantDomain
namespace Domains.ApplicantDomain;
public enum MaritalStatus
{
public enum MaritalStatus
{
Other,
Married,
Unmarried,
Separated,
WidowOrWidower
}
}
Other,
Married,
Unmarried,
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
/// <remarks>Owned</remarks>
public class Name
{
public string FirstName { get; set; } = null!;
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
/// <remarks>Owned</remarks>
public class Passport
{
/// Number of <see cref="Passport"/>
public string Number { get; set; } = null!;
/// Number of <see cref="Passport"/>
public string Number { get; set; } = null!;
/// Issuing authority of <see cref="Passport"/>
public string Issuer { get; set; } = null!;
/// Issuing authority of <see cref="Passport"/>
public string Issuer { get; set; } = null!;
/// Date of issue
public DateTime IssueDate { get; set; }
/// Date of issue
public DateTime IssueDate { get; set; }
/// Date when the <see cref="Passport"/> expires
public DateTime ExpirationDate { get; set; }
}
}
/// Date when the <see cref="Passport"/> expires
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
public string Name { get; set; } = null!;
/// Name of hirer
public string Name { get; set; } = null!;
/// <see cref="ApplicantDomain.Address"/> of hirer
public Address Address { get; set; } = null!;
/// <see cref="ApplicantDomain.Address"/> of hirer
public Address Address { get; set; } = null!;
/// Phone number of hirer
public string PhoneNum { get; set; } = null!;
}
}
/// Phone number of hirer
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 interface IEntity
{
public Guid Id { get; }
}
}
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
public class City : IEntity
{
/// Unique identifier of the <see cref="City"/>
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
public string Name { get; set; } = null!;
/// Name of the city
public string Name { get; set; } = null!;
/// <see cref="LocationDomain.Country"/> in which the city is located
public Country Country { get; set; } = null!;
}
}
/// <see cref="LocationDomain.Country"/> in which the city is located
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
public class Country : IEntity
{
/// Unique identifier of the <see cref="Country"/>
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
public string Name { get; set; } = null!;
/// Name of the country
public string Name { get; set; } = null!;
/// Located in Schengen area
public bool IsSchengen { get; set; }
/// Located in Schengen area
public bool IsSchengen { get; set; }
/// List of <see cref="City"/> that country have
public List<City> Cities { get; set; } = null!;
}
}
/// List of <see cref="City"/> that country have
public List<City> Cities { get; set; } = null!;
}

View File

@@ -1,20 +1,17 @@
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
public class PastVisa : IEntity
{
/// Unique identifier of <see cref="PastVisa"/>
public Guid Id { get; private set; } = Guid.NewGuid();
/// Date of issue
public DateTime IssueDate { get; set; }
/// Date of issue
public DateTime IssueDate { get; set; }
/// Name of visa
public string Name { get; set; } = null!;
/// Name of visa
public string Name { get; set; } = null!;
/// Date when visa expires
public DateTime ExpirationDate { get; set; }
}
/// Date when visa expires
public DateTime ExpirationDate { get; set; }
}

View File

@@ -1,17 +1,14 @@
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
public class PastVisit : IEntity
{
/// Unique identifier of <see cref="PastVisit"/>
public Guid Id { get; private set; } = Guid.NewGuid();
/// First day of <see cref="PastVisit"/>
public DateTime StartDate { get; set; }
/// First day of <see cref="PastVisit"/>
public DateTime StartDate { get; set; }
/// Last day of <see cref="PastVisit"/>
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
{
/// Permission to enter the destination country
/// <remarks>Owned</remarks>
public class PermissionToDestCountry
{
/// Date when <see cref="PermissionToDestCountry"/> expires
public DateTime ExpirationDate { get; set; }
namespace Domains.VisaApplicationDomain;
/// Issuing authority
public string Issuer { get; set; } = null!;
}
}
/// 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
public string Issuer { get; set; } = null!;
}

View File

@@ -1,13 +1,12 @@
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!;
namespace Domains.VisaApplicationDomain;
/// Date when <see cref="ReentryPermit"/> expires
public DateTime ExpirationDate { get; set; }
}
}
/// 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
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
public enum RequestedNumberOfEntries
{
Many,
One,
Two
}
}
Many,
One,
Two
}

View File

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

View File

@@ -2,18 +2,17 @@
using Microsoft.EntityFrameworkCore;
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)
.HasMaxLength(100);
entity.Property(p => p.Building)
.IsUnicode(false)
.HasMaxLength(10);
}
entity.Property(p => p.Street)
.IsUnicode(false)
.HasMaxLength(100);
entity.Property(p => p.Building)
.IsUnicode(false)
.HasMaxLength(10);
}
}
}

View File

@@ -2,26 +2,25 @@
using Microsoft.EntityFrameworkCore;
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.FatherName);
entity.OwnsOne(p => p.MotherName);
entity.OwnsOne(p => p.Passport);
entity.OwnsOne(p => p.Name);
entity.OwnsOne(p => p.FatherName);
entity.OwnsOne(p => p.MotherName);
entity.OwnsOne(p => p.Passport);
entity.Property(p => p.Citizenship)
.IsUnicode(false)
.HasMaxLength(30);
entity.Property(p => p.Citizenship)
.IsUnicode(false)
.HasMaxLength(30);
entity.Property(p => p.CitizenshipByBirth)
.IsUnicode(false)
.HasMaxLength(30);
}
entity.Property(p => p.CitizenshipByBirth)
.IsUnicode(false)
.HasMaxLength(30);
}
}
}

View File

@@ -2,23 +2,22 @@
using Microsoft.EntityFrameworkCore;
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)
.HasMaxLength(50);
entity.Property(p => p.FirstName)
.IsUnicode(false)
.HasMaxLength(50);
entity.Property(p => p.Surname)
.IsUnicode(false)
.HasMaxLength(50);
entity.Property(p => p.Surname)
.IsUnicode(false)
.HasMaxLength(50);
entity.Property(p => p.Patronymic)
.IsUnicode(false)
.HasMaxLength(50);
}
entity.Property(p => p.Patronymic)
.IsUnicode(false)
.HasMaxLength(50);
}
}
}

View File

@@ -2,19 +2,18 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
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);
namespace Infrastructure.Database.Applicants.Configuration;
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
}
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)
.IsUnicode(false)
.HasMaxLength(200);
}
}
}

View File

@@ -2,21 +2,20 @@
using Microsoft.EntityFrameworkCore;
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)
.IsUnicode(false)
.HasMaxLength(200);
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(200);
entity.Property(p => p.PhoneNum)
.IsUnicode(false)
.HasMaxLength(20);
}
entity.Property(p => p.PhoneNum)
.IsUnicode(false)
.HasMaxLength(20);
}
}
}

View File

@@ -2,21 +2,20 @@
using Infrastructure.Database.Generic;
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"/>
/// <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()
{
protected override IQueryable<Applicant> LoadDomain()
{
return base.LoadDomain()
.Include(a => a.CountryOfBirth)
.Include(a => a.CityOfBirth)
.Include(a => a.PlaceOfWork);
}
return base.LoadDomain()
.Include(a => a.CountryOfBirth)
.Include(a => a.CityOfBirth)
.Include(a => a.PlaceOfWork);
}
}
}

View File

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

View File

@@ -2,39 +2,38 @@
using Infrastructure.Database.Generic;
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)
: Microsoft.EntityFrameworkCore.DbContext(opts), IGenericWriter, IGenericReader, IUnitOfWork
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
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);
}
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);
}
}

View File

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

View File

@@ -2,52 +2,51 @@
using Infrastructure.Database.GeneralExceptions;
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
/// <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
/// <inheritdoc cref="IGenericRepository{T}.GetAllAsync"/>
public async Task<List<T>> GetAllAsync(CancellationToken cancellationToken)
=> await LoadDomain().ToListAsync(cancellationToken);
/// <inheritdoc cref="IGenericRepository{T}.GetOneAsync"/>
public async Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken)
{
/// <inheritdoc cref="IGenericRepository{T}.GetAllAsync"/>
public async Task<List<T>> GetAllAsync(CancellationToken cancellationToken)
=> 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>();
}
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>();
}
}

View File

@@ -1,12 +1,11 @@
using Domains;
namespace Infrastructure.Database.Generic
namespace Infrastructure.Database.Generic;
/// Reads from data storage
public interface IGenericReader
{
/// Reads from data storage
public interface IGenericReader
{
/// 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;
}
}
/// 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;
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>
/// Generic repository pattern
/// Update entity in storage
/// </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);
/// <param name="entity">Entity to update</param>
Task UpdateAsync(T entity, CancellationToken cancellationToken);
/// Get one entity with specific id
/// <param name="id">Identifier of entity</param>
Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Remove entity from storage
/// </summary>
/// <param name="entity">Entity to remove</param>
void Remove(T entity);
/// Add entity to storage
/// <param name="entity">Entity to add</param>
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);
}
}
/// Save changes in storage
Task SaveAsync(CancellationToken cancellationToken);
}

View File

@@ -1,25 +1,24 @@
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
/// <remarks><see cref="IUnitOfWork"/> should be used to save changes</remarks>
public interface IGenericWriter
{
/// Add entity to data storage
/// <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;
/// Add entity to data storage
/// <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
/// <param name="entity">Entity to update</param>
/// <typeparam name="T">Entity type</typeparam>
void Update<T>(T entity) where T : class, IEntity;
/// Update entity in data storage
/// <param name="entity">Entity to update</param>
/// <typeparam name="T">Entity type</typeparam>
void Update<T>(T entity) where T : class, IEntity;
/// Remove entity from data storage
/// <param name="entity">Entity to remove</param>
/// <typeparam name="T">Entity type</typeparam>
void Remove<T>(T entity) where T : class, IEntity;
}
}
/// Remove entity from data storage
/// <param name="entity">Entity to remove</param>
/// <typeparam name="T">Entity type</typeparam>
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>
Task SaveAsync(CancellationToken cancellationToken);
}
}
/// Saves changes in data storage
/// <param name="cancellationToken">Cancellation Token</param>
Task SaveAsync(CancellationToken cancellationToken);
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
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)
.HasMaxLength(70);
}
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
}
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
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)
.HasMaxLength(70);
}
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
}
}

View File

@@ -2,14 +2,13 @@
using Infrastructure.Database.Generic;
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)
: GenericRepository<City>(reader, writer, unitOfWork), ICitiesRepository
protected override IQueryable<City> LoadDomain()
{
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 Infrastructure.Database.Generic;
namespace Infrastructure.Database.Locations.Repositories.Cities
{
public interface ICitiesRepository : IGenericRepository<City> { }
}
namespace Infrastructure.Database.Locations.Repositories.Cities;
public interface ICitiesRepository : IGenericRepository<City> { }

View File

@@ -2,14 +2,13 @@
using Infrastructure.Database.Generic;
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)
: GenericRepository<Country>(reader, writer, unitOfWork), ICountriesRepository
protected override IQueryable<Country> LoadDomain()
{
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 Infrastructure.Database.Generic;
namespace Infrastructure.Database.Locations.Repositories.Countries
{
public interface ICountriesRepository : IGenericRepository<Country> { }
}
namespace Infrastructure.Database.Locations.Repositories.Countries;
public interface ICountriesRepository : IGenericRepository<Country> { }

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
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)
.HasMaxLength(70);
}
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
}
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
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)
.HasMaxLength(200);
}
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
}
}
}

View File

@@ -2,15 +2,14 @@
using Microsoft.EntityFrameworkCore;
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)
.HasMaxLength(25);
}
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(25);
}
}
}

View File

@@ -2,21 +2,22 @@
using Microsoft.EntityFrameworkCore;
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)
.WithMany(a => a.VisaApplications)
.HasForeignKey(va => va.ApplicantId)
.IsRequired();
entity.HasOne(va => va.Applicant)
.WithMany(a => a.VisaApplications)
.HasForeignKey(va => va.ApplicantId)
.IsRequired();
entity.OwnsOne(p => p.ReentryPermit);
entity.OwnsOne(p => p.PermissionToDestCountry);
}
entity.OwnsOne(p => p.ReentryPermit);
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 Infrastructure.Database.Generic;
namespace Infrastructure.Database.VisaApplications.Repositories
{
public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> { }
}
namespace Infrastructure.Database.VisaApplications.Repositories;
public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> { }

View File

@@ -2,17 +2,16 @@
using Infrastructure.Database.Generic;
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)
: GenericRepository<VisaApplication>(reader, writer, unitOfWork), IVisaApplicationsRepository
protected override IQueryable<VisaApplication> LoadDomain()
{
protected override IQueryable<VisaApplication> LoadDomain()
{
return base.LoadDomain()
.Include(a => a.DestinationCountry)
.Include(a => a.PastVisas)
.Include(a => a.PastVisits);
}
return base.LoadDomain()
.Include(a => a.DestinationCountry)
.Include(a => a.PastVisas)
.Include(a => a.PastVisits);
}
}
}

View File

@@ -8,28 +8,27 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
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
public static class DependencyInjection
/// Add services needed for Infrastructure layer
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
{
/// Add services needed for Infrastructure layer
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
{
//TODO строка подключения
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<IGenericWriter>(serviceProvider => serviceProvider.GetRequiredService<DbContext>());
services.AddScoped<IUnitOfWork>(serviceProvider => serviceProvider.GetRequiredService<DbContext>());
services.AddScoped<IGenericReader>(serviceProvider => serviceProvider.GetRequiredService<DbContext>());
services.AddScoped<IGenericWriter>(serviceProvider => serviceProvider.GetRequiredService<DbContext>());
services.AddScoped<IUnitOfWork>(serviceProvider => serviceProvider.GetRequiredService<DbContext>());
services.AddScoped<IApplicantsRepository, ApplicantsRepository>();
services.AddScoped<IVisaApplicationsRepository, VisaApplicationsRepository>();
services.AddScoped<ICitiesRepository, CitiesRepository>();
services.AddScoped<ICountriesRepository, CountriesRepository>();
services.AddScoped<IApplicantsRepository, ApplicantsRepository>();
services.AddScoped<IVisaApplicationsRepository, VisaApplicationsRepository>();
services.AddScoped<ICitiesRepository, CitiesRepository>();
services.AddScoped<ICountriesRepository, CountriesRepository>();
return services;
}
return services;
}
}
}

View File

@@ -1,31 +1,30 @@
using System.Reflection;
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
public static class DependencyInjection
/// Add needed services
public static IServiceCollection RegisterServices(this IServiceCollection services)
{
/// Add needed services
public static IServiceCollection RegisterServices(this IServiceCollection services)
{
services
.AddInfrastructure()
.AddPresentation();
services
.AddInfrastructure()
.AddPresentation();
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));
});
}
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));
});
}
}

View File

@@ -1,5 +1,4 @@
namespace SchengenVisaApi;
#pragma warning disable CS1591
public class Program
{
@@ -14,4 +13,4 @@ public class Program
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
public static class PipelineRequest
/// Configure middleware
public static WebApplication ConfigurePipelineRequest(this WebApplication app)
{
/// Configure middleware
public static WebApplication ConfigurePipelineRequest(this WebApplication app)
{
app.UseSwagger()
.UseSwaggerUI();
app.UseSwagger()
.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseHttpsRedirection();
app.MapControllers();
app.MapControllers();
return app;
}
return app;
}
}
}