GenHTTP icon indicating copy to clipboard operation
GenHTTP copied to clipboard

Allow any module feature to be directly added to layouts

Open Kaliumhexacyanoferrat opened this issue 1 month ago • 4 comments

As a developer of a web application, I would like to define the layout of my app using as few code a possible (while still being expressive).

Example

Create some kind of thing within the API (e.g. ILayoutBuilder) that all other modules can use to attach their convenience methods using extensions.

var layout = Layout.Create()
                        .AddContent("content", Resource.FromFile(...)) // = Content.From(...)
                        .AddDownload("file.pdf", Resource.FromFile(...))
                        .AddStaticResources("files", Tree.From(...))
                        .AddSinglePageApplication(Tree.From(...));

The extensions should be part of the providing module (e.g. for Content in Content.Extensions.cs).

We could also provide even higher level APIs such as .AddStaticResources("files", DirectoryInfo).

Acceptance criteria

  • There is an interface that other modules can reference (via the API) to add extensions
  • All modules provide suitable extension methods to simplify their usage on layouts
  • The concept is documented on both the layouting modules as well as the providing modules on the GenHTTP website
  • The concept is documented in the contribution guidelines
  • The feature is covered by acceptance tests

Kaliumhexacyanoferrat avatar Nov 21 '25 16:11 Kaliumhexacyanoferrat

@Matasx, @MDA2AV how do you feel about this one? This is already available for some modules such as web services, but I think it would be nice to have this as a general mechanism, eliminating the dependencies on the layouting module as well.

Kaliumhexacyanoferrat avatar Nov 21 '25 16:11 Kaliumhexacyanoferrat

So basically having a similar mechanism as ASP.NET Core does with IServiceCollection where you can create extensions to it and then call them at the builder?

I think we have the IHandlerBuilder to work out something similar but it requires to call the .Add() so the ILayoutBuilder could be more clean

MDA2AV avatar Nov 21 '25 16:11 MDA2AV

IServiceCollection is more comparable to IHostBuilder, placing it on layouts is more flexibel. IHandlerBuilder does not feature routing (this is mainly provided by layouts), so it would need to add an intermediate layout anyway as some kind of concern there.

Kaliumhexacyanoferrat avatar Nov 21 '25 17:11 Kaliumhexacyanoferrat

I like the convenience, though I don't have a strong opinion. My acceptance criteria for the code are basically:

  1. easy to write
  2. easy to understand

To which I would give a pass here. 🙂

Matasx avatar Nov 21 '25 17:11 Matasx