Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for SuppressImplicitRequiredAttributeForNonNullableReferenceTypes #39

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Wemogy.AspNet/Startup/StartupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ namespace Wemogy.AspNet.Startup
{
public static class StartupExtensions
{
public static void GetWemogyDefaultControllerOptions(MvcOptions options)
/// <summary>
/// Set the default <see cref="MvcOptions"/> settings for Controllers in wemogy applications.
/// </summary>
/// <param name="options">The <see cref="MvcOptions"/> to update.</param>
/// <param name="suppressImplicitRequiredAttributeForNonNullableReferenceTypes">The <see cref="Microsoft.AspNetCore.Mvc.MvcOptions.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes"/> property for all contollers.</param>
public static void GetWemogyDefaultControllerOptions(MvcOptions options, bool suppressImplicitRequiredAttributeForNonNullableReferenceTypes = false)
{
options.SuppressAsyncSuffixInActionNames = false;
options.InputFormatters.Insert(0, new RawBodyInputFormatter());
options.Conventions.Add(new RouteTokenTransformerConvention(new KebabCaseParameterTransformer()));
options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = suppressImplicitRequiredAttributeForNonNullableReferenceTypes;
}

public static void AddDefaultControllers(this IServiceCollection serviceCollection, bool addDapr = false)
public static void AddDefaultControllers(this IServiceCollection serviceCollection, bool addDapr = false, bool suppressImplicitRequiredAttributeForNonNullableReferenceTypes = false)
{
var builder = serviceCollection.AddControllers(options => GetWemogyDefaultControllerOptions(options));
var builder = serviceCollection.AddControllers(options => GetWemogyDefaultControllerOptions(options, suppressImplicitRequiredAttributeForNonNullableReferenceTypes));
builder.AddWemogyJsonOptions();

if (addDapr)
Expand All @@ -48,7 +54,7 @@ public static void AddDefaultSetup(this IServiceCollection serviceCollection, St
serviceCollection.AddDefaultMonitoring(options.MonitoringEnvironment);
}

serviceCollection.AddDefaultControllers(options.DaprEnvironment != null);
serviceCollection.AddDefaultControllers(options.DaprEnvironment != null, options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes);

serviceCollection.AddDefaultRouting();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Wemogy.AspNet/Startup/StartupOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class StartupOptions
internal DaprEnvironment? DaprEnvironment { get; private set; }
internal HashSet<Type> Middlewares { get; private set; }

/// <summary>
/// Sets the <see cref="Microsoft.AspNetCore.Mvc.MvcOptions.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes"/> property for all contollers.
/// </summary>
public bool SuppressImplicitRequiredAttributeForNonNullableReferenceTypes { get; set; }

public StartupOptions()
{
Middlewares = new HashSet<Type>();
Expand Down