diff --git a/InertiaCore/Response.cs b/InertiaCore/Response.cs
index 7bdd2cb..2082a03 100644
--- a/InertiaCore/Response.cs
+++ b/InertiaCore/Response.cs
@@ -4,6 +4,7 @@
using InertiaCore.Models;
using InertiaCore.Props;
using InertiaCore.Utils;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
@@ -60,9 +61,10 @@ protected internal async Task ProcessResponse()
var props = _props;
props = ResolveSharedProps(props);
+ props = ResolveInertiaPropertyProviders(props);
props = ResolvePartialProperties(props);
props = ResolveAlways(props);
- props = await ResolvePropertyInstances(props);
+ props = await ResolvePropertyInstances(props, _context!.HttpContext.Request);
return props;
}
@@ -79,6 +81,32 @@ protected internal async Task ProcessResponse()
return props;
}
+ ///
+ /// Resolve properties from objects implementing ProvidesInertiaProperties.
+ ///
+ private Dictionary ResolveInertiaPropertyProviders(Dictionary props)
+ {
+ var context = new RenderContext(_component, _context!.HttpContext.Request);
+
+ foreach (var pair in props.ToList())
+ {
+ if (pair.Value is ProvidesInertiaProperties provider)
+ {
+ // Remove the provider object itself
+ props.Remove(pair.Key);
+
+ // Add the properties it provides
+ var providedProps = provider.ToInertiaProperties(context);
+ foreach (var providedProp in providedProps)
+ {
+ props[providedProp.Key] = providedProp.Value;
+ }
+ }
+ }
+
+ return props;
+ }
+
///
/// Resolve the `only` and `except` partial request props.
///
@@ -147,7 +175,7 @@ protected internal async Task ProcessResponse()
///
/// Resolve all necessary class instances in the given props.
///
- private static async Task> ResolvePropertyInstances(Dictionary props)
+ private static async Task> ResolvePropertyInstances(Dictionary props, HttpRequest request)
{
return (await Task.WhenAll(props.Select(async pair =>
{
@@ -158,12 +186,13 @@ protected internal async Task ProcessResponse()
Func