Files
mixtape/zero.Api/ServiceCollectionExtensions.cs
T
2021-11-29 18:25:50 +01:00

30 lines
786 B
C#

using Microsoft.Extensions.DependencyInjection;
namespace zero.Api;
public static class ServiceCollectionExtensions
{
public static ZeroBuilder AddApi<T>(this ZeroBuilder builder) where T : ZeroApiPlugin, IZeroPlugin, new()
{
return builder.AddApi<T>(_ => { });
}
public static ZeroBuilder AddApi(this ZeroBuilder builder)
{
return builder.AddApi<ZeroApiPlugin>();
}
public static ZeroBuilder AddApi<T>(this ZeroBuilder builder, Action<ApiOptions> options) where T : ZeroApiPlugin, IZeroPlugin, new()
{
return builder.AddPlugin(services =>
{
T plugin = new();
plugin.PostConfigureServices = (services, configuration) =>
{
services.Configure<ApiOptions>(opts => options(opts));
};
return plugin;
});
}
}