Skip to content

Commit

Permalink
Merge pull request #12 from MahdiyarGHD/develop
Browse files Browse the repository at this point in the history
Fix memory leak
  • Loading branch information
Ali-YousefiTelori authored Oct 7, 2023
2 parents d42f514 + 493924b commit 22f7fb1
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 8 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace EasyMicroservices.AuthenticationsMicroservice.Migrations
{
/// <inheritdoc />
public partial class SyncDatabaseForProduction : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserName = table.Column<string>(type: "nvarchar(450)", nullable: true),
Password = table.Column<string>(type: "nvarchar(max)", nullable: true),
UniqueIdentity = table.Column<string>(type: "nvarchar(450)", nullable: true, collation: "SQL_Latin1_General_CP1_CS_AS"),
CreationDateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
ModificationDateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
DeletedDateTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});

migrationBuilder.CreateIndex(
name: "IX_Users_CreationDateTime",
table: "Users",
column: "CreationDateTime");

migrationBuilder.CreateIndex(
name: "IX_Users_DeletedDateTime",
table: "Users",
column: "DeletedDateTime");

migrationBuilder.CreateIndex(
name: "IX_Users_IsDeleted",
table: "Users",
column: "IsDeleted");

migrationBuilder.CreateIndex(
name: "IX_Users_ModificationDateTime",
table: "Users",
column: "ModificationDateTime");

migrationBuilder.CreateIndex(
name: "IX_Users_UniqueIdentity",
table: "Users",
column: "UniqueIdentity");

migrationBuilder.CreateIndex(
name: "IX_Users_UserName",
table: "Users",
column: "UserName",
unique: true,
filter: "[UserName] IS NOT NULL");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<bool>("IsUsernameVerified")
.HasColumnType("bit");
b.Property<DateTime?>("ModificationDateTime")
.HasColumnType("datetime2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ namespace EasyMicroservices.AuthenticationsMicroservice
{
public class DatabaseBuilder : IDatabaseBuilder
{
readonly IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
IConfiguration _configuration;
public DatabaseBuilder(IConfiguration configuration)
{
_configuration = configuration;
}

public void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using EasyMicroservices.AuthenticationsMicroservice.Database.Contexts;
using System;
using System.Linq;
using Microsoft.Extensions.Configuration;

namespace EasyMicroservices.AuthenticationsMicroservice
{
Expand All @@ -32,7 +33,9 @@ public virtual IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestCon

public virtual IDatabase GetDatabase()
{
return new EntityFrameworkCoreDatabaseProvider(new AuthenticationsContext(new DatabaseBuilder()));
var _config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();

return new EntityFrameworkCoreDatabaseProvider(new AuthenticationsContext(new DatabaseBuilder(_config)));
}

public static string DefaultUniqueIdentity { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static async Task Main(string[] args)

builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<IDependencyManager>(service => new DependencyManager());
builder.Services.AddScoped<IDatabaseBuilder>(serviceProvider => new DatabaseBuilder());
builder.Services.AddScoped<IDatabaseBuilder>(serviceProvider => new DatabaseBuilder(_config));
builder.Services.AddScoped(service => new WhiteLabelManager(service, service.GetService<IDependencyManager>()));
builder.Services.AddScoped<IJWTManager, JWTManager>();
builder.Services.AddScoped((serviceProvider) => new DependencyManager().GetContractLogic<UserEntity, AddUserRequestContract, UserContract, UserContract>());
Expand Down Expand Up @@ -145,7 +145,9 @@ public static async Task Main(string[] args)

static void CreateDatabase()
{
using (var context = new AuthenticationsContext(new DatabaseBuilder()))
var _config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();

using (var context = new AuthenticationsContext(new DatabaseBuilder(_config)))
{
if (context.Database.EnsureCreated())
{
Expand Down

0 comments on commit 22f7fb1

Please sign in to comment.