Plugga.Core 1.3.1

Plugga.Core lets you quickly create modular ASP .Net Core applications searching, loading and configuring any "pluggable" component. Pluggable components are a little set of commonly used objects as Controllers, DbContexts, Razor Pages, SignalR Hubs, HostedServices, static assets and, of course, your own component objects.

Install-Package Plugga.Core -Version 1.3.1
dotnet add package Plugga.Core --version 1.3.1
<PackageReference Include="Plugga.Core" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugga.Core --version 1.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Plugga.Core, 1.3.1"
For F# scripts that support #r syntax, copy this into the source code to reference the package.

Plugga.Core

Plugga.Core lets you quickly create modular ASP .Net Core applications searching, loading and configuring any "pluggable" component. Pluggable components are a little set of commonly used objects as Controllers, DbContexts, Razor Pages, SignalR Hubs, HostedServices, static assets and, of course, your own component objects.

Plugga.Core has been developed with the followings targets in mind:

  1. Speed up the development/deploy process:
    1. Avoiding to spend time setting up the project
    2. Concentrating the effort on the result
    3. Allowing parallel development of components
  2. Reuse and share components as far as possible
  3. Have a "ready to grow" modular application

The following enanchements/features are into the "to do list":

  • Ordered pipeline (or using predefined hooks)
  • Built-in authorization/authentication handling
  • Multi tenant handling
    ... and, of course, any suggestion from you.

Do you want to try it?

Just take a look at Plugga.Core.Templates

How does it works

Let's assume we have the following (runtime) file system structure:

.
├───YouAppFolder
│   │   YourApp.exe
│   │   ... Plugga.Core and all other dependencies
│   ├───Log
│   ├───Pluggables
│   │   ├───Component1
│   │   │   │   Pluggable.Component1.dll
│   │   │   │   Pluggable.Component1.Views.dll
│   │   │   └───wwwroot
│   │   │       │   ...
│   │   │       ...
│   │   ...
│   │   └───ComponentN
│   │           Pluggable.ComponentN.dll
│   └───wwwroot
│       │   ...
│       ...
...

This structure is composed by:

  1. YourApp which uses the Plugga.Core
  2. Plugga.Core and app dependencies
  3. N Components

YourApp

It is the entry point. The basic form of YourApp can be represented as follow:

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Plugga.Core.Extensions.Hosting;
using System.Threading.Tasks;

namespace YourApp
{
    public class Program
    {
        public static async Task Main(string[] args) => await new HostBuilder().Plugga().Build().RunAsync();
    }
}

Plugga.Core

When the Plugga() method is executed, the following steps are performed:

  1. The main configuration file (appsettings.json) and all pluggable specific configuration files are loaded.
  2. The logger, based on Serilog, is built and configured according to the main configuration file.

Note: Plugga.Core offers a built-in implementations for overriding logging levels based on the component category. Components category can be also logged using the Class parameter within the output template.
3. The current working directory is set as "assembly resolver" for any shared dependecies required by the app components.
4. Kestrel is configured according to the main configuration file.
5. IIS integration is enabled.
6. Path containing the "pluggable" components is read from the configuration file.
7. Pluggable services are discovered and added to ASP .Net Core dependency injection system (see the Components section below).

Note: In order to allow you to add your own services, you can implements the IPluggable interface. The method ConfigureServices will be executed.
8. The ASP .Net pipeline is configured.
Note: In order to allow you to add your own middlewares, you can implements the IPluggable interface. The method Configure will be executed.
9. Enable static file serving
Note: If a wwwroot directory exists into a component directory, its contents is published. For instance, the file YourAppFolder\Pluggables\Component1\wwwroot\favicon.ico is available at http://localhost:5123/Component1/favicon.ico

Components

A component is just a library based on the ASP .Net Core Web App template.
The following types are automatically "handled".

Microsoft.Extensions.Hosting.IHostedService

Used to run background services.
Please refer to the official documentation for details.

Microsoft.EntityFrameworkCore.DbContext

Used to represents a database session.
Please refer to the official documentation for details.
Actually Plugga.Core offers a built-in support via Attributes to the following databases:

Sqlite
PluggableServiceDbContextSqliteOptionsAttribute(string ConnectionString, ServiceLifetime ContextLifetime, ServiceLifetime OptionsLifetime)

The ConnectionString is the name of a connection string stored into the configuration file.
If it is not specified, the name DefaultSqlite is used.
The ContextLifetime and the OptionsLifetime used as default is ServiceLifetime.Scoped.

SqlServer
PluggableServiceDbContextSqlServerOptionsAttribute(string ConnectionString, ServiceLifetime ContextLifetime, ServiceLifetime OptionsLifetime)

The ConnectionString is the name of a connection string stored into the configuration file.
If it is not specified, the name DefaultSqlServer is used.
The ContextLifetime and the OptionsLifetime used as default is ServiceLifetime.Scoped.

InMemory
PluggableServiceDbContextInMemoryOptionsAttribute(string ConnectionString, ServiceLifetime ContextLifetime, ServiceLifetime OptionsLifetime)

The ConnectionString is the name of a connection string stored into the configuration file.
If it is not specified, the name DefaultInMemory is used.
The ContextLifetime and the OptionsLifetime used as default is ServiceLifetime.Scoped.

Cosmos
PluggableServiceDbContextCosmosOptionsAttribute(string ConnectionString, ServiceLifetime ContextLifetime, ServiceLifetime OptionsLifetime, string AccountEndpoint, string AccountKey)

The ConnectionString is the name of a connection string stored into the configuration file.
If it is not specified, the name DefaultCosmos is used.
The ContextLifetime and the OptionsLifetime used as default is ServiceLifetime.Scoped.
The AccountEndpoint and the AccountKey must be set accordingly to your own subscription.

Microsoft.AspNetCore.Mvc.ControllerBase

A base class for an MVC controller without view support.
Please refer to the official documentation for details.

Microsoft.AspNetCore.Mvc.RazorPages.Page

A base class for a Razor page.
Please refer to the official documentation for details.

WARNING
There is an important convention to keep in mind when you create Razor pages.
You MUST add your pages under Pages\YourComponent\YourPage.cshtml in order to make your page available at http://localhost:5123/YourComponent/YourPage

Microsoft.AspNetCore.SignalR.Hub

A base class for a SignalR hub.
Please refer to the official documentation for details.

Plugga.Core.Interfaces.IPluggable

Used to allow you to manually intervene on the dependencies registration and/or on the pipeline configuration.

Dependecies registration
public void ConfigureServices(IServiceCollection services, IConfiguration configuration, ILogger logger)  
Pipeline Configuration
public void Configure(IApplicationBuilder applicationBuilder, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, ILogger logger)

Note: Actually you can add your middlewares only before the standard ones. Moreover your middlewares are added as they are discovered (which means based on their directory name, alphabetically sorted).

wwwroot

Used to publish static files.

Example: Referring to the above file system structure publish:

  • YourAppFolder\wwwroot at http://localhost:5123/
  • YourAppFolder\Component1\wwwroot at http://localhost:5123/Component1/

Plugga.Core

Plugga.Core lets you quickly create modular ASP .Net Core applications searching, loading and configuring any "pluggable" component. Pluggable components are a little set of commonly used objects as Controllers, DbContexts, Razor Pages, SignalR Hubs, HostedServices, static assets and, of course, your own component objects.

Plugga.Core has been developed with the followings targets in mind:

  1. Speed up the development/deploy process:
    1. Avoiding to spend time setting up the project
    2. Concentrating the effort on the result
    3. Allowing parallel development of components
  2. Reuse and share components as far as possible
  3. Have a "ready to grow" modular application

The following enanchements/features are into the "to do list":

  • Ordered pipeline (or using predefined hooks)
  • Built-in authorization/authentication handling
  • Multi tenant handling
    ... and, of course, any suggestion from you.

Do you want to try it?

Just take a look at Plugga.Core.Templates

How does it works

Let's assume we have the following (runtime) file system structure:

.
├───YouAppFolder
│   │   YourApp.exe
│   │   ... Plugga.Core and all other dependencies
│   ├───Log
│   ├───Pluggables
│   │   ├───Component1
│   │   │   │   Pluggable.Component1.dll
│   │   │   │   Pluggable.Component1.Views.dll
│   │   │   └───wwwroot
│   │   │       │   ...
│   │   │       ...
│   │   ...
│   │   └───ComponentN
│   │           Pluggable.ComponentN.dll
│   └───wwwroot
│       │   ...
│       ...
...

This structure is composed by:

  1. YourApp which uses the Plugga.Core
  2. Plugga.Core and app dependencies
  3. N Components

YourApp

It is the entry point. The basic form of YourApp can be represented as follow:

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Plugga.Core.Extensions.Hosting;
using System.Threading.Tasks;

namespace YourApp
{
    public class Program
    {
        public static async Task Main(string[] args) => await new HostBuilder().Plugga().Build().RunAsync();
    }
}

Plugga.Core

When the Plugga() method is executed, the following steps are performed:

  1. The main configuration file (appsettings.json) and all pluggable specific configuration files are loaded.
  2. The logger, based on Serilog, is built and configured according to the main configuration file.

Note: Plugga.Core offers a built-in implementations for overriding logging levels based on the component category. Components category can be also logged using the Class parameter within the output template.
3. The current working directory is set as "assembly resolver" for any shared dependecies required by the app components.
4. Kestrel is configured according to the main configuration file.
5. IIS integration is enabled.
6. Path containing the "pluggable" components is read from the configuration file.
7. Pluggable services are discovered and added to ASP .Net Core dependency injection system (see the Components section below).

Note: In order to allow you to add your own services, you can implements the IPluggable interface. The method ConfigureServices will be executed.
8. The ASP .Net pipeline is configured.
Note: In order to allow you to add your own middlewares, you can implements the IPluggable interface. The method Configure will be executed.
9. Enable static file serving
Note: If a wwwroot directory exists into a component directory, its contents is published. For instance, the file YourAppFolder\Pluggables\Component1\wwwroot\favicon.ico is available at http://localhost:5123/Component1/favicon.ico

Components

A component is just a library based on the ASP .Net Core Web App template.
The following types are automatically "handled".

Microsoft.Extensions.Hosting.IHostedService

Used to run background services.
Please refer to the official documentation for details.

Microsoft.EntityFrameworkCore.DbContext

Used to represents a database session.
Please refer to the official documentation for details.
Actually Plugga.Core offers a built-in support via Attributes to the following databases:

Sqlite
PluggableServiceDbContextSqliteOptionsAttribute(string ConnectionString, ServiceLifetime ContextLifetime, ServiceLifetime OptionsLifetime)

The ConnectionString is the name of a connection string stored into the configuration file.
If it is not specified, the name DefaultSqlite is used.
The ContextLifetime and the OptionsLifetime used as default is ServiceLifetime.Scoped.

SqlServer
PluggableServiceDbContextSqlServerOptionsAttribute(string ConnectionString, ServiceLifetime ContextLifetime, ServiceLifetime OptionsLifetime)

The ConnectionString is the name of a connection string stored into the configuration file.
If it is not specified, the name DefaultSqlServer is used.
The ContextLifetime and the OptionsLifetime used as default is ServiceLifetime.Scoped.

InMemory
PluggableServiceDbContextInMemoryOptionsAttribute(string ConnectionString, ServiceLifetime ContextLifetime, ServiceLifetime OptionsLifetime)

The ConnectionString is the name of a connection string stored into the configuration file.
If it is not specified, the name DefaultInMemory is used.
The ContextLifetime and the OptionsLifetime used as default is ServiceLifetime.Scoped.

Cosmos
PluggableServiceDbContextCosmosOptionsAttribute(string ConnectionString, ServiceLifetime ContextLifetime, ServiceLifetime OptionsLifetime, string AccountEndpoint, string AccountKey)

The ConnectionString is the name of a connection string stored into the configuration file.
If it is not specified, the name DefaultCosmos is used.
The ContextLifetime and the OptionsLifetime used as default is ServiceLifetime.Scoped.
The AccountEndpoint and the AccountKey must be set accordingly to your own subscription.

Microsoft.AspNetCore.Mvc.ControllerBase

A base class for an MVC controller without view support.
Please refer to the official documentation for details.

Microsoft.AspNetCore.Mvc.RazorPages.Page

A base class for a Razor page.
Please refer to the official documentation for details.

WARNING
There is an important convention to keep in mind when you create Razor pages.
You MUST add your pages under Pages\YourComponent\YourPage.cshtml in order to make your page available at http://localhost:5123/YourComponent/YourPage

Microsoft.AspNetCore.SignalR.Hub

A base class for a SignalR hub.
Please refer to the official documentation for details.

Plugga.Core.Interfaces.IPluggable

Used to allow you to manually intervene on the dependencies registration and/or on the pipeline configuration.

Dependecies registration
public void ConfigureServices(IServiceCollection services, IConfiguration configuration, ILogger logger)  
Pipeline Configuration
public void Configure(IApplicationBuilder applicationBuilder, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, ILogger logger)

Note: Actually you can add your middlewares only before the standard ones. Moreover your middlewares are added as they are discovered (which means based on their directory name, alphabetically sorted).

wwwroot

Used to publish static files.

Example: Referring to the above file system structure publish:

  • YourAppFolder\wwwroot at http://localhost:5123/
  • YourAppFolder\Component1\wwwroot at http://localhost:5123/Component1/

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.1 48 1/22/2021
1.0.3 55 1/22/2021
1.0.2 89 10/19/2020
1.0.1 123 10/17/2020
1.0.0 126 9/17/2020