@websolutespa backend modules.
dotnet new web -n testApp
You can also create it in Visual Studio selecting the ASP.NET Core Empty
template.
cd testApp
dotnet add package Ws.Core
You can install the Ws.Core
package using the NuGet Package Manager in Visual Studio.
You can also add the project reference in your solution to work with the source code you downloaded.
cd testApp
dotnet dotnet add reference [<WS_CORE_PROJECT_PATH>]
You can add a reference to the Ws.Core
source code you downloaded using the Visual Studio IDE.
The easiest way to create a Ws.Core
application is to replace everything inside the Program.cs
with just the CreateRunBuilder
method call.
Ws.Core.Program.CreateRunBuilder<Ws.Core.AppConfig>(args);
This method will use the default Startup
class to register all the installed Ws.Core.Extension
services in the container, add all the middleware components in the pipeline and run the application using NLog integration as default.
If you need to add custom configurations check the following examples.
In this example we are passing custom parameters to the CreateRunBuilder
method.
Ws.Core.Program.CreateRunBuilder<Ws.Core.AppConfig>(
testApp.Program.ParseArgs(args),
testApp.Program.setupBuilder,
testApp.Program.setupApplication
);
namespace testApp
{
public partial class Program : WebApplicationFactory<Program>
{
internal static Action<WebApplicationBuilder> setupBuilder = (builder) => Add(builder);
internal static Action<WebApplication> setupApplication = (app) => { Use(app); ConfigureServer(app); };
internal static void Add(WebApplicationBuilder builder)
{
// Add services to the container.
}
internal static void Use(WebApplication app)
{
// Add middleware components to the pipeline
}
internal static string[] ParseArgs(string[] args)
{
// Custom args parsing
return args;
}
internal static void ConfigureServer(WebApplication app)
{
// Configure host/others features
}
}
}
In this example we are using the CreateBuilder
method and a custom Startup
class.
var builder = Ws.Core.Program.CreateBuilder(args);
// Add logging
builder.Logging.AddConsole();
// Use your Startup class
var startup = new testApp.Startup(builder);
startup.Add(builder);
var app = builder.Build();
startup.Use(app);
app.Run();
namespace testApp
{
public class Startup : Ws.Core.Startup<Ws.Core.AppConfig>
{
public Startup(WebApplicationBuilder builder) : base(builder) { }
public override void Add(WebApplicationBuilder builder)
{
base.Add(builder);
// Add services to the container.
}
public override void Use(WebApplication app)
{
base.Use(app);
// Add middleware components to the pipeline
}
}
}
Now that your Ws.Core
application is up and running you can start developing your features by installing one or more available modules from the ws-core module list or creating your own modules or extensions following the ExtensionBase module usage guide section.
Using the Ws.Core
extension ecosystem you can install and configure modules and extension directly from a centralized json file called ext-settings.json
.
Create the empty file in your project root folder using the following model and see the ExtensionBase module configuration section to learn how to write your custom configuration.
{
"$schema": "https://raw.githubusercontent.com/massimodipaolo/ws-core/master/src/modules/json-schema.json",
"extConfig": {
"folder": "Extensions",
"enableShutDownOnChange": false,
"assemblies": {},
"injectors": []
}
}