46 lines
2.3 KiB
C#
46 lines
2.3 KiB
C#
using MicroForge.CLI.Commands.Interfaces;
|
|
using MicroForge.CLI.Features;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace MicroForge.CLI.Extensions;
|
|
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddServices(this IServiceCollection services, string[] args)
|
|
{
|
|
services.AddScoped<ArgsContext>(_ => new ArgsContext { Args = args });
|
|
services.AddScoped<ProjectContext>();
|
|
services.AddScoped<IFeature, Api>();
|
|
services.AddScoped<IFeature, Orm>();
|
|
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddCommands(this IServiceCollection services)
|
|
{
|
|
// Register "m4g"
|
|
services.AddScoped<Commands.MicroForge>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge>, Commands.MicroForge.Init>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge>, Commands.MicroForge.Run>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge>, Commands.MicroForge.Install>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge>, Commands.MicroForge.Uninstall>();
|
|
|
|
// Register "m4g add"
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge>, Commands.MicroForge.Add>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge.Add>, Commands.MicroForge.Add.Api>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge.Add>, Commands.MicroForge.Add.Orm>();
|
|
|
|
// Register "m4g generate"
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge>, Commands.MicroForge.Generate>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge.Generate>, Commands.MicroForge.Generate.Entity>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge.Generate>, Commands.MicroForge.Generate.Router>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge.Generate>, Commands.MicroForge.Generate.Migration>();
|
|
|
|
// Register "m4g migrations"
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge>, Commands.MicroForge.Migrations>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge.Migrations>, Commands.MicroForge.Migrations.Apply>();
|
|
services.AddScoped<ISubCommandOf<Commands.MicroForge.Migrations>, Commands.MicroForge.Migrations.Rollback>();
|
|
|
|
return services;
|
|
}
|
|
} |