This small feature is useful for build a monolithic application from multiple separated features. Developers can register services and configure their modules by themselves.
Firstly, you need to implement the class that inherits from ModuleStartup for your features.
using Juice.Modular;
...
namespace Juice.Test
{
[Feature(Required = true)]
public class TestModuleStartup : ModuleStartup{
// override ConfigureServices
public override void ConfigureServices(IServiceCollection services, IMvcBuilder mvc, IWebHostEnvironment env, IConfigurationRoot configuration)
{
// configure your services
}
// override Configure
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IWebHostEnvironment env)
{
// configure application pipeline
}
// override OnShutdown
public override void OnShutdown(IServiceProvider serviceProvider, IWebHostEnvironment env)
{
// release resources
}
}
}
The Feature attribute’s arguments:
Required: specify this feature is required and will start automatically
Name: specify your feature’s name. If it’s not defined, the default name will be used. The default name will be namespace then replace the “.” with “_”.
Ex: Your namespace is Juice.Test so the feature name will be Juice_Test by default.
Description: describe your feature
Dependencies: an array of dependent features
IncompatibleFeatures: an array of incompatible features. The application will throw an exception on startup if incompatible features are registered, so you must try to solve.
Then in your Program.cs
using Juice.Modular;
...
var builder = WebApplication.CreateBuilder(args);
builder.AddDiscoveredModules();
...
var app = builder.Build();
// customize application's middlewares order
// app.UseMultiTenant();
// app.UseRouting();
...
app.ConfigureDiscoveredModules();
...
app.Run();