Plugga.Core
1.5.0
dotnet add package Plugga.Core --version 1.5.0
NuGet\Install-Package Plugga.Core -Version 1.5.0
<PackageReference Include="Plugga.Core" Version="1.5.0" />
paket add Plugga.Core --version 1.5.0
#r "nuget: Plugga.Core, 1.5.0"
// Install Plugga.Core as a Cake Addin #addin nuget:?package=Plugga.Core&version=1.5.0 // Install Plugga.Core as a Cake Tool #tool nuget:?package=Plugga.Core&version=1.5.0
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 is compatible. 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. |
-
net5.0
- Microsoft.AspNetCore.Components.WebAssembly.Server (>= 5.0.8)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 5.0.8)
- Microsoft.AspNetCore.SignalR.Client (>= 5.0.8)
- Microsoft.EntityFrameworkCore (>= 5.0.8)
- Microsoft.EntityFrameworkCore.Cosmos (>= 5.0.8)
- Microsoft.EntityFrameworkCore.InMemory (>= 5.0.8)
- Microsoft.EntityFrameworkCore.Sqlite (>= 5.0.8)
- Microsoft.EntityFrameworkCore.SqlServer (>= 5.0.8)
- Newtonsoft.Json (>= 13.0.1)
- Newtonsoft.Json.Bson (>= 1.0.2)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 5.0.7)
- Serilog.Extensions.Logging (>= 3.0.1)
- Serilog.Settings.Configuration (>= 3.1.0)
- Serilog.Sinks.Console (>= 4.0.0)
- Serilog.Sinks.File (>= 5.0.0)
- Serilog.Sinks.MSSqlServer (>= 5.6.0)
- 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.