Skip to content

Commit

Permalink
Add a convention to bind JourneyInstance properties by default
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Oct 5, 2023
1 parent f36411c commit 119ea87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace TeachingRecordSystem.SupportUi.Infrastructure.Conventions;

public class BindJourneyInstancePropertiesConvention : IPageApplicationModelConvention
{
public void Apply(PageApplicationModel model)
{
var journeyInstanceProperties = model.HandlerProperties.Where(p =>
p.ParameterType == typeof(JourneyInstance) ||
(p.ParameterType.IsGenericType && p.ParameterType.GetGenericTypeDefinition() == typeof(JourneyInstance<>)));

foreach (var journeyInstanceProperty in journeyInstanceProperties)
{
journeyInstanceProperty.BindingInfo ??= new BindingInfo();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using TeachingRecordSystem.Core.Infrastructure.Configuration;
using TeachingRecordSystem.SupportUi;
using TeachingRecordSystem.SupportUi.Infrastructure;
using TeachingRecordSystem.SupportUi.Infrastructure.Conventions;
using TeachingRecordSystem.SupportUi.Infrastructure.Filters;
using TeachingRecordSystem.SupportUi.Infrastructure.FormFlow;
using TeachingRecordSystem.SupportUi.Infrastructure.ModelBinding;
Expand Down Expand Up @@ -103,6 +104,8 @@
builder.Services
.AddRazorPages(options =>
{
options.Conventions.Add(new BindJourneyInstancePropertiesConvention());

options.Conventions.AddFolderApplicationModelConvention(
"/Persons/PersonDetail",
model =>
Expand Down

0 comments on commit 119ea87

Please sign in to comment.