ardalis / modulith

Modulith is a dotnet new template for Modular Monoliths. It streamlines the creation of new .Net solutions and the addition of modules to existing ones.
MIT License
118 stars 11 forks source link

--WithUi functionality #48

Open PeterKneale opened 1 month ago

PeterKneale commented 1 month ago

suggestion

With modular monoliths I find that the ui needs of different modules varies quite a lot. ie: Some might show a dashboard or graph, others a razor page with a few forms, those with more complex requirements a blazor ui. It would be helpful to support a few rendering methods for the modules.

current behaviour

You can generate a solution with a Blazor UI by using the --WithUi

dotnet new modulith --add basic-module --with-name Shipments --to eShop --WithUi

suggested behaviour

.... a Blazor UI by using the --with-ui blazor .... a Razor Pages UI by using the --with-ui razor

dotnet new modulith --add basic-module --with-name Shipments --to eShop --with-ui blazor
dotnet new modulith --add basic-module --with-name Dashboard--to eShop --with-ui razor

also of note

Here is an example of how multiple modules containing razor pages can be composed into a single web application.

My example repo: https://github.com/PeterKneale/modular_monolith_saas/blob/main/src/Micro.Web/Program.cs#L53

https://learn.microsoft.com/en-us/aspnet/core/mvc/advanced/app-parts?view=aspnetcore-8.0

builder.Services
    .AddControllersWithViews()
    .AddApplicationPart(UsersWebAssemblyInfo.Assembly)
    .AddApplicationPart(TenantsWebAssemblyInfo.Assembly)
    .AddApplicationPart(TranslationsWebAssemblyInfo.Assembly)
    .AddRazorRuntimeCompilation();

builder.Services.Configure<MvcRazorRuntimeCompilationOptions>(options =>
{
    options.FileProviders.Add(new EmbeddedFileProvider(UsersWebAssemblyInfo.Assembly));
    options.FileProviders.Add(new EmbeddedFileProvider(TenantsWebAssemblyInfo.Assembly));
    options.FileProviders.Add(new EmbeddedFileProvider(TranslationsWebAssemblyInfo.Assembly));
});.
david-acm commented 1 month ago

@PeterKneale Thanks for the suggestion. It does make sense to provide several UI options, Modulith is meant to be extensible, so we could add a template to generate the UI with razor pages. The closest thing we support to razor pages is blazor with server-side rendering. Even though it runs a different architecture, simple static content can still be rendered using blazor components which use razor syntax.

Do you have examples of needs that might not be satisfied with blazor?

Would you be interested in contributing the template? I can provide a starting point template.config for a razor template

PeterKneale commented 1 month ago

@david-acm Thanks for the reply and putting this repo together, I had a good look through how you were constructing your dotnet template and decided to try making one of my own. No need to add razor page support for my benefit

If its of interest: https://github.com/PeterKneale/modular_monolith_template