Files
mixtape/zero.Backoffice/ServiceCollectionExtensions.cs
T

30 lines
863 B
C#
Raw Normal View History

2021-11-23 22:56:22 +01:00
using Microsoft.Extensions.DependencyInjection;
namespace zero.Backoffice;
public static class ServiceCollectionExtensions
{
public static ZeroBuilder AddBackoffice<T>(this ZeroBuilder builder) where T : ZeroBackofficePlugin, IZeroPlugin, new()
{
2021-11-29 00:38:55 +01:00
return builder.AddBackoffice<T>(_ => { });
2021-11-23 22:56:22 +01:00
}
public static ZeroBuilder AddBackoffice(this ZeroBuilder builder)
{
return builder.AddBackoffice<ZeroBackofficePlugin>();
}
public static ZeroBuilder AddBackoffice<T>(this ZeroBuilder builder, Action<BackofficeOptions> options) where T : ZeroBackofficePlugin, IZeroPlugin, new()
{
2021-11-27 16:33:05 +01:00
return builder.AddPlugin(services =>
2021-11-23 22:56:22 +01:00
{
2021-11-27 16:33:05 +01:00
T plugin = new();
2021-11-23 22:56:22 +01:00
plugin.PostConfigureServices = (services, configuration) =>
{
services.Configure<BackofficeOptions>(opts => options(opts));
};
return plugin;
});
}
}