Skip to content

Commit c90ae43

Browse files
committed
Added "ConfigureSession" option to InertiaOptions
1 parent 3674e54 commit c90ae43

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

InertiaNetCore/Extensions/Configure.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNetCore.Mvc;
88
using Microsoft.AspNetCore.Mvc.ViewFeatures;
99
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Options;
1011

1112
namespace InertiaNetCore.Extensions;
1213

@@ -40,21 +41,24 @@ public static IApplicationBuilder UseInertia(this IApplicationBuilder app)
4041
}
4142

4243
public static IServiceCollection AddInertia(this IServiceCollection services,
43-
Action<InertiaOptions>? options = null, bool flashEnabled = true)
44+
Action<InertiaOptions>? options = null)
4445
{
4546
services.AddHttpContextAccessor();
4647
services.AddHttpClient();
4748

4849
services.AddSingleton<SsrGateway>();
4950
services.AddSingleton<ResponseFactory>();
5051

51-
if (flashEnabled)
52-
services.AddSession();
5352

5453
services.Configure<MvcOptions>(mvcOptions => { mvcOptions.Filters.Add<InertiaActionFilter>(); });
5554

56-
if (options != null)
55+
if (options != null)
56+
{
5757
services.Configure(options);
58+
}
59+
60+
var opts = services.BuildServiceProvider().GetRequiredService<IOptions<InertiaOptions>>().Value;
61+
services.AddSession(opts.ConfigureSession);
5862

5963
return services;
6064
}

InertiaNetCore/Models/InertiaOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json;
22
using System.Text.Json.Serialization;
3+
using Microsoft.AspNetCore.Builder;
34

45
namespace InertiaNetCore.Models;
56

@@ -10,6 +11,8 @@ public class InertiaOptions
1011
public bool SsrEnabled { get; set; } = false;
1112
public string SsrUrl { get; set; } = "http://127.0.0.1:13714/render";
1213

14+
public Action<SessionOptions> ConfigureSession { get; set; } = _ => { };
15+
1316
private static JsonSerializerOptions DefaultJsonSerializerOptions { get; } = new()
1417
{
1518
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,

0 commit comments

Comments
 (0)