Plugga.Core
1.3.1
See the version list below for details.
dotnet add package Plugga.Core --version 1.3.1
NuGet\Install-Package Plugga.Core -Version 1.3.1
<PackageReference Include="Plugga.Core" Version="1.3.1" />
paket add Plugga.Core --version 1.3.1
#r "nuget: Plugga.Core, 1.3.1"
// Install Plugga.Core as a Cake Addin #addin nuget:?package=Plugga.Core&version=1.3.1 // Install Plugga.Core as a Cake Tool #tool nuget:?package=Plugga.Core&version=1.3.1
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:
- Speed up the development/deploy process:
- Avoiding to spend time setting up the project
- Concentrating the effort on the result
- Allowing parallel development of components
- Reuse and share components as far as possible
- 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:
- YourApp which uses the Plugga.Core
- Plugga.Core and app dependencies
- 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:
- The main configuration file (appsettings.json) and all pluggable specific configuration files are loaded.
- 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 methodConfigureServices
will be executed. 8. The ASP .Net pipeline is configured. Note: In order to allow you to add your own middlewares, you can implements theIPluggable
interface. The methodConfigure
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/
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.Components.WebAssembly.Server (>= 3.2.1)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 3.1.9)
- Microsoft.AspNetCore.SignalR.Client (>= 3.1.9)
- Microsoft.EntityFrameworkCore (>= 3.1.9)
- Microsoft.EntityFrameworkCore.Cosmos (>= 3.1.9)
- Microsoft.EntityFrameworkCore.InMemory (>= 3.1.9)
- Microsoft.EntityFrameworkCore.Sqlite (>= 3.1.9)
- Microsoft.EntityFrameworkCore.SqlServer (>= 3.1.9)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 3.1.4)
- Serilog.Extensions.Logging (>= 3.0.1)
- Serilog.Settings.Configuration (>= 3.1.0)
- Serilog.Sinks.Console (>= 3.1.1)
- Serilog.Sinks.File (>= 4.1.0)
- Serilog.Sinks.MSSqlServer (>= 5.5.1)
- Serilog.Sinks.MySQL (>= 4.0.0)
- Serilog.Sinks.SQLite (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.