-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add-Migration, Set InvariantGlobalization to false for update-database.
Register Dependencies.
- Loading branch information
1 parent
077b6cd
commit 587b51e
Showing
9 changed files
with
532 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using FluentValidation; | ||
using MediatR; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using SwiftLink.Application.Behaviors; | ||
using SwiftLink.Application.Common; | ||
using SwiftLink.Application.Common.Interfaces; | ||
using System.Reflection; | ||
|
||
namespace SwiftLink.Application; | ||
|
||
public static class ConfigServices | ||
{ | ||
public static IServiceCollection RegisterApplicationServices(this IServiceCollection services) | ||
{ | ||
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); | ||
services.AddMediatR(config => | ||
{ | ||
config.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); | ||
config.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); | ||
}); | ||
|
||
services.AddScoped<IShortCodeGenerator, TimeBasedShortCodeGenerator>(); | ||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using SwiftLink.Infrastructure.CacheProvider; | ||
using SwiftLink.Infrastructure.Persistence.Context; | ||
|
||
namespace SwiftLink.Infrastructure; | ||
|
||
/// <summary> | ||
/// This extention is programmed for registering Infrastructure services . | ||
/// </summary> | ||
public static class ConfigureServices | ||
{ | ||
public static IServiceCollection RegisterInfrastructureServices(this IServiceCollection services, | ||
IConfiguration configuration) | ||
{ | ||
services.AddDbContext<IApplicationDbContext, ApplicationDbContext>(opt => | ||
{ | ||
opt.UseSqlServer( | ||
configuration.GetConnectionString(nameof(ApplicationDbContext)), | ||
(db) => | ||
{ | ||
db.MigrationsHistoryTable("MigrationHistory"); | ||
}) | ||
.LogTo(Console.WriteLine, LogLevel.Information); | ||
}); | ||
|
||
services.AddSingleton<ICacheProvider, RedisCacheService>(); | ||
services.AddStackExchangeRedisCache(opt => | ||
{ | ||
opt.Configuration = configuration["AppSettings:RedisCacheUrl"]; | ||
}); | ||
|
||
return services; | ||
} | ||
} |
170 changes: 170 additions & 0 deletions
170
src/SwiftLink.Infrastructure/Migrations/20240109132423_Init.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
src/SwiftLink.Infrastructure/Migrations/20240109132423_Init.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace SwiftLink.Infrastructure.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class Init : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.EnsureSchema( | ||
name: "Base"); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "Subscriber", | ||
schema: "Base", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(type: "int", nullable: false) | ||
.Annotation("SqlServer:Identity", "1, 1"), | ||
Token = table.Column<Guid>(type: "uniqueidentifier", nullable: false), | ||
Name = table.Column<string>(type: "varchar(50)", unicode: false, maxLength: 50, nullable: false), | ||
IsActive = table.Column<bool>(type: "bit", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Base_Subscriber", x => x.Id); | ||
}, | ||
comment: "Only these subscribers are allowed to insert a URL to obtain a shorter one."); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "Link", | ||
schema: "Base", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(type: "int", nullable: false) | ||
.Annotation("SqlServer:Identity", "1, 1"), | ||
SubscriberId = table.Column<int>(type: "int", nullable: false), | ||
ShortCode = table.Column<string>(type: "varchar(16)", unicode: false, maxLength: 16, nullable: false), | ||
OriginalUrl = table.Column<string>(type: "varchar(1500)", unicode: false, maxLength: 1500, nullable: false), | ||
Description = table.Column<string>(type: "varchar(250)", unicode: false, maxLength: 250, nullable: false), | ||
ExpirationDate = table.Column<DateTime>(type: "datetime2", nullable: false), | ||
IsBanned = table.Column<bool>(type: "bit", nullable: false), | ||
Password = table.Column<string>(type: "varchar(25)", unicode: false, maxLength: 25, nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Base_Link", x => x.Id); | ||
table.ForeignKey( | ||
name: "FK_Link_Subscriber_SubscriberId", | ||
column: x => x.SubscriberId, | ||
principalSchema: "Base", | ||
principalTable: "Subscriber", | ||
principalColumn: "Id"); | ||
}, | ||
comment: "Stores Original links and generated shortCode."); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "LinkVisit", | ||
schema: "Base", | ||
columns: table => new | ||
{ | ||
Id = table.Column<long>(type: "bigint", nullable: false) | ||
.Annotation("SqlServer:Identity", "1, 1"), | ||
LinkId = table.Column<int>(type: "int", nullable: false), | ||
Date = table.Column<DateTime>(type: "datetime2", nullable: false), | ||
ClientMetaData = table.Column<string>(type: "varchar(500)", unicode: false, maxLength: 500, nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Base_LinkVisit", x => x.Id); | ||
table.ForeignKey( | ||
name: "FK_LinkVisit_Link_LinkId", | ||
column: x => x.LinkId, | ||
principalSchema: "Base", | ||
principalTable: "Link", | ||
principalColumn: "Id"); | ||
}, | ||
comment: "analytics, providing insights into the number of users who clicked on a shortened link."); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Link_SubscriberId", | ||
schema: "Base", | ||
table: "Link", | ||
column: "SubscriberId"); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_LinkVisit_LinkId", | ||
schema: "Base", | ||
table: "LinkVisit", | ||
column: "LinkId"); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "LinkVisit", | ||
schema: "Base"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "Link", | ||
schema: "Base"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "Subscriber", | ||
schema: "Base"); | ||
} | ||
} | ||
} |
Oops, something went wrong.