-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f72601
commit f3f1bbb
Showing
14 changed files
with
193 additions
and
7 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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
...ules/Question/Modules.Question.Infrastructure/Data/Configuration/QuestionConfiguration.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,19 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Modules.Question.Infrastructure.Data.Configuration; | ||
internal sealed class QuestionConfiguration : IEntityTypeConfiguration<Core.QuestionAggregate.Question> | ||
{ | ||
public void Configure(EntityTypeBuilder<Core.QuestionAggregate.Question> builder) | ||
{ | ||
builder.Property(x => x.QuestionId) | ||
.ValueGeneratedOnAdd(); | ||
|
||
builder.Property(x => x.AskedQuestion) | ||
.HasMaxLength(300) | ||
.IsRequired(); | ||
|
||
builder.Property(x => x.Discussion) | ||
.HasMaxLength(600); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...uestion/Modules.Question.Infrastructure/Data/Configuration/QuestionOptionConfiguration.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,19 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Modules.Question.Core.QuestionAggregate; | ||
|
||
namespace Modules.Question.Infrastructure.Data.Configuration; | ||
internal sealed class QuestionOptionConfiguration : IEntityTypeConfiguration<QuestionOption> | ||
{ | ||
public void Configure(EntityTypeBuilder<QuestionOption> builder) | ||
{ | ||
builder.Property(x => x.QuestionId) | ||
.ValueGeneratedOnAdd(); | ||
|
||
builder.Property(x => x.OptionText) | ||
.HasMaxLength(200) | ||
.IsRequired(); | ||
|
||
builder.HasQueryFilter(x => x.DeletedDate == null); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...uestion/Modules.Question.Infrastructure/Data/Configuration/QuestionSetTagConfiguration.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,21 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Modules.Question.Core.QuestionAggregate; | ||
|
||
namespace Modules.Question.Infrastructure.Data.Configuration; | ||
internal sealed class QuestionSetTagConfiguration : IEntityTypeConfiguration<QuestionSetTag> | ||
{ | ||
public void Configure(EntityTypeBuilder<QuestionSetTag> builder) | ||
{ | ||
builder | ||
.HasKey(x => new { x.QuestionSetId, x.TagId }); | ||
|
||
builder.HasOne(x => x.QuestionSet) | ||
.WithMany(x => x.QuestionSetTags) | ||
.HasForeignKey(x => x.QuestionSetId); | ||
|
||
builder.HasOne(x => x.Tag) | ||
.WithMany(x => x.QuestionSetTags) | ||
.HasForeignKey(x => x.TagId); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
...odules.Question.Infrastructure/QuestionModuleInfrastructureServiceCollectionExtensions.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,45 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Modules.Question.Application.Common; | ||
using Modules.Question.Infrastructure.Data; | ||
using Serilog; | ||
using System.Reflection; | ||
|
||
namespace Modules.Question.Infrastructure; | ||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection RegisterQuestionModuleInfrastructure(this IServiceCollection services, | ||
ILogger logger, | ||
IConfiguration configuration, | ||
List<Assembly> mediatRAssembly) | ||
{ | ||
mediatRAssembly.Add(typeof(ServiceCollectionExtensions).Assembly); | ||
services.AddDbContext<QuestionModuleDbContext>((sp, opt) => | ||
{ | ||
opt.UseSqlServer(configuration.GetConnectionString("QuestionModuleDbContext"), optBuilder => | ||
{ | ||
optBuilder.EnableRetryOnFailure(10); | ||
optBuilder.MigrationsHistoryTable(QuestionModuleConstants.MigrationHistoryTableName, | ||
QuestionModuleConstants.SchemaName); | ||
optBuilder.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery); | ||
}); | ||
}); | ||
logger.Information("Question module db context registered"); | ||
return services; | ||
} | ||
|
||
public static IApplicationBuilder MigrateQuestionModuleDatabase(this IApplicationBuilder app) | ||
{ | ||
var scopedService = app.ApplicationServices.CreateScope(); | ||
var dbContext = scopedService.ServiceProvider.GetRequiredService<QuestionModuleDbContext>(); | ||
|
||
if (dbContext.Database.IsSqlServer()) | ||
{ | ||
dbContext.Database.Migrate(); | ||
} | ||
|
||
return app; | ||
} | ||
} |