Gestalt.ASPNet.RazorPages 1.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package Gestalt.ASPNet.RazorPages --version 1.0.8
NuGet\Install-Package Gestalt.ASPNet.RazorPages -Version 1.0.8
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gestalt.ASPNet.RazorPages" Version="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gestalt.ASPNet.RazorPages --version 1.0.8
#r "nuget: Gestalt.ASPNet.RazorPages, 1.0.8"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Gestalt.ASPNet.RazorPages as a Cake Addin
#addin nuget:?package=Gestalt.ASPNet.RazorPages&version=1.0.8

// Install Gestalt.ASPNet.RazorPages as a Cake Tool
#tool nuget:?package=Gestalt.ASPNet.RazorPages&version=1.0.8

<img src="https://jacraig.github.io/Gestalt/images/Icon.png" style="height:25px" alt="Gestalt Icon" /> Gestalt

.NET Publish Coverage Status

Gestalt is a C# library designed to facilitate the development of modular applications. It allows developers to create reusable modules that can be easily integrated into various applications, enhancing code reusability and maintainability.

Table of Contents

Introduction

Modern software development often requires building applications with modular architectures to promote reusability and scalability. Gestalt provides a framework for organizing application functionality into cohesive modules, encapsulating logic and services that can be easily shared across different projects.

Features

  • Modular Architecture: Define modules encapsulating configuration, services, and lifecycle events.
  • Configuration Management: Easily configure application settings using built-in configuration providers.
  • Dependency Injection: Utilize dependency injection for managing dependencies and services.
  • Lifecycle Management: Implement lifecycle events such as application start, stop, and shutdown.

Getting Started

Installation

Gestalt can be installed via NuGet Package Manager:

dotnet add package Gestalt.Core

Or for framework specific functionality, install the appropriate package:

# For ASP.NET base functionality
dotnet add package Gestalt.AspNet
# For ASP.NET MVC functionality
dotnet add package Gestalt.AspNet.MVC
# For ASP.NET Controllers functionality (without views)
dotnet add package Gestalt.AspNet.Controllers
# For ASP.NET SignalR functionality
dotnet add package Gestalt.AspNet.SignalR
# For ASP.NET Razor Pages functionality
dotnet add package Gestalt.AspNet.RazorPages
# For console applications
dotnet add package Gestalt.Console

Creating Modules

To create a module, follow these steps:

  1. Define a class that inherits from one of the *ModuleBaseClasses or implements one of the IApplicationModule interfaces (IMvcModule, ISignalRModule, IRazorPagesModule, etc).

  2. Override methods for configuring settings, services, and lifecycle events.

  3. Implement module-specific functionality within the class.

A basic example of a module class is shown below:

/// <summary>
/// This is an example of a basic module that configures the application with the usual default settings when creating a new web application.
/// It implements the MvcModuleBaseClass which simplifies the process of creating a module that needs to modify MVC settings.
/// However, you can implement the IMvcModule interface directly if you prefer.
/// </summary>
public class BasicModule : MvcModuleBaseClass<BasicModule>
{
    /// <summary>
    /// This is called to configure the IApplicationBuilder object. Since this is an MVC app, that would be the WebApplication object.
    /// </summary>
    /// <param name="applicationBuilder">The application builder object.</param>
    /// <param name="configuration">The configuration object.</param>
    /// <param name="environment">The host environment object.</param>
    /// <returns>The application builder object should be returned.</returns>
    public override IApplicationBuilder? ConfigureApplication(IApplicationBuilder? applicationBuilder, IConfiguration? configuration, IHostEnvironment? environment)
    {
        if (applicationBuilder is null)
            return applicationBuilder;

        // Configure the HTTP request pipeline.
        if (environment?.IsDevelopment() == false)
        {
            // This is the default exception handler for the application when in production.
            _ = applicationBuilder.UseExceptionHandler("/Home/Error");

            // We will add a strict transport security header to the response.
            _ = applicationBuilder.UseHsts();
        }

        // This will redirect HTTP requests to HTTPS.
        _ = applicationBuilder.UseHttpsRedirection();
        // And let's serve static files.
        _ = applicationBuilder.UseStaticFiles();
        // We will also add authorization to the application.
        _ = applicationBuilder.UseAuthorization();
        // And lastly, we will return the application builder.
        return applicationBuilder;
    }

    /// <summary>
    /// This is called to configure the MVC options. We will just return the options object as is.
    /// </summary>
    /// <param name="mVCBuilder">The MVC builder object.</param>
    /// <param name="configuration">The configuration object.</param>
    /// <param name="environment">The host environment object.</param>
    /// <returns>The MVC builder object.</returns>
    public override IMvcBuilder? ConfigureMVC(IMvcBuilder? mVCBuilder, IConfiguration? configuration, IHostEnvironment? environment)
    {
        return mVCBuilder;
    }

    /// <summary>
    /// This is called to configure our endpoint routes. For our example, we will just use the default route.
    /// </summary>
    /// <param name="endpoints">The endpoint route builder.</param>
    /// <param name="configuration">The configuration object.</param>
    /// <param name="environment">The host environment object.</param>
    /// <returns>The endpoint route builder.</returns>
    public override IEndpointRouteBuilder? ConfigureRoutes(IEndpointRouteBuilder? endpoints, IConfiguration? configuration, IHostEnvironment? environment)
    {
        if (endpoints is null)
            return endpoints;

        // Map the default route.
        endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");

        return endpoints;
    }
}

Using Modules

To have your application start using modules, you just need to call UseGestalt on the application builder:

// Program.cs
public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);
        var app = builder.UseGestalt<ExampleModule>();
        app.Run();
    }
}

For more advanced usage, refer to the documentation.

Contributing

Contributions to Gestalt are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request. Before contributing, please review the contribution guidelines.

License

Gestalt is licensed under the Apache 2.0 License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.11 18 5/1/2024
1.0.10 71 5/1/2024
1.0.9 81 4/29/2024
1.0.8 87 4/12/2024
1.0.7 95 4/11/2024
1.0.6 85 3/30/2024
1.0.5 84 3/28/2024
1.0.4 91 3/26/2024
1.0.3 80 3/26/2024
1.0.2 96 3/26/2024
1.0.1 92 3/22/2024