Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jacraig/gestalt

Gestalt is a comprehensive application module system designed to streamline the development and packaging process of applications. With Gestalt, effortlessly construct robust applications using modular design principles and leverage the power of dependency injection for seamless integration of reusable components.
https://github.com/jacraig/gestalt

asp-net modular reusable-components

Last synced: about 1 month ago
JSON representation

Gestalt is a comprehensive application module system designed to streamline the development and packaging process of applications. With Gestalt, effortlessly construct robust applications using modular design principles and leverage the power of dependency injection for seamless integration of reusable components.

Awesome Lists containing this project

README

        

# Gestalt Icon Gestalt

[![.NET Publish](https://github.com/JaCraig/Gestalt/actions/workflows/dotnet-publish.yml/badge.svg)](https://github.com/JaCraig/Gestalt/actions/workflows/dotnet-publish.yml) [![Coverage Status](https://coveralls.io/repos/github/JaCraig/Gestalt/badge.svg?branch=main)](https://coveralls.io/github/JaCraig/Gestalt?branch=main)

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](#introduction)
- [Features](#features)
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Creating Modules](#creating-modules)
- [Using Modules](#using-modules)
- [Contributing](#contributing)
- [License](#license)

## 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:

```bash
dotnet add package Gestalt.Core
```

Or for framework specific functionality, install the appropriate package:

```bash
# 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:

```csharp
///
/// 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.
///
public class BasicModule : MvcModuleBaseClass
{
///
/// This is called to configure the IApplicationBuilder object. Since this is an MVC app, that would be the WebApplication object.
///
/// The application builder object.
/// The configuration object.
/// The host environment object.
/// The application builder object should be returned.
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;
}

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

///
/// This is called to configure our endpoint routes. For our example, we will just use the default route.
///
/// The endpoint route builder.
/// The configuration object.
/// The host environment object.
/// The endpoint route builder.
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:

```csharp
// Program.cs
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
var app = builder.UseGestalt(args);
app.Run();
}
}
```
For more advanced usage, refer to the [documentation](https://jacraig.github.io/Gestalt/articles/intro.html).

## 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](https://github.com/JaCraig/Gestalt/blob/main/CONTRIBUTING.md).

## License

Gestalt is licensed under the [Apache 2.0 License](https://github.com/JaCraig/Gestalt/blob/main/LICENSE).