diff --git a/src/Sitko.Core.App.Web/WebApplicationExtensions.cs b/src/Sitko.Core.App.Web/WebApplicationExtensions.cs index 918f32d87..d66750922 100644 --- a/src/Sitko.Core.App.Web/WebApplicationExtensions.cs +++ b/src/Sitko.Core.App.Web/WebApplicationExtensions.cs @@ -5,7 +5,11 @@ namespace Sitko.Core.App.Web; -public class SitkoCoreWebApplicationBuilder : SitkoCoreApplicationBuilder +public interface ISitkoCoreWebApplicationBuilder : ISitkoCoreApplicationBuilder +{ +} + +public class SitkoCoreWebApplicationBuilder : SitkoCoreServerApplicationBuilder, ISitkoCoreWebApplicationBuilder { private readonly WebApplicationBuilder webApplicationBuilder; @@ -31,13 +35,14 @@ protected override void ConfigureHostBuilder(Applicatio public static class WebApplicationExtensions { - public static SitkoCoreApplicationBuilder AddSitkoCore(this WebApplicationBuilder builder) => + public static ISitkoCoreWebApplicationBuilder AddSitkoCore(this WebApplicationBuilder builder) => builder.AddSitkoCore(Array.Empty()); - public static SitkoCoreApplicationBuilder AddSitkoCore(this WebApplicationBuilder builder, string[] args) + public static ISitkoCoreWebApplicationBuilder AddSitkoCore(this WebApplicationBuilder builder, string[] args) { builder.Services.TryAddTransient(); - return new SitkoCoreWebApplicationBuilder(builder, args); + return ApplicationBuilderFactory.GetOrCreateApplicationBuilder(builder, + applicationBuilder => new SitkoCoreWebApplicationBuilder(applicationBuilder, args)); } public static WebApplication MapSitkoCore(this WebApplication webApplication) diff --git a/src/Sitko.Core.App/Application.cs b/src/Sitko.Core.App/Application.cs deleted file mode 100644 index c8dbb4a21..000000000 --- a/src/Sitko.Core.App/Application.cs +++ /dev/null @@ -1,215 +0,0 @@ -// using System.Text.Json; -// using JetBrains.Annotations; -// using Microsoft.Extensions.Configuration; -// using Microsoft.Extensions.DependencyInjection; -// using Microsoft.Extensions.Hosting; -// using Microsoft.Extensions.Logging; -// -// namespace Sitko.Core.App; -// -// public abstract class Application : IApplication -// { -// // private readonly List moduleRegistrations = -// // new(); -// -// //private readonly Dictionary store = new(); -// //private bool disposed; -// -// protected Application(string[] args) -// { -// //Args = args; -// //AddModule(); -// } -// -// -// protected string[] Args { get; set; } -// -// public static string OptionsKey => nameof(Application); -// -// public Guid Id { get; } = Guid.NewGuid(); -// -// -// // public string Name => GetApplicationOptions().Name; -// // public string Version => GetApplicationOptions().Version; -// -// // public async ValueTask DisposeAsync() -// // { -// // if (disposed) -// // { -// // return; -// // } -// // -// // await DisposeAsync(true); -// // GC.SuppressFinalize(this); -// // disposed = true; -// // } -// -// protected virtual ValueTask DisposeAsync(bool disposing) => new(); -// -// [PublicAPI] -// //public ApplicationOptions GetApplicationOptions() => GetContext().Options; -// -// -// -// protected virtual void ConfigureHostConfiguration(IConfigurationBuilder configurationBuilder) -// { -// } -// -// protected virtual void ConfigureAppConfiguration(HostBuilderContext context, -// IConfigurationBuilder configurationBuilder) -// { -// } -// -// -// [PublicAPI] -// //public Dictionary GetModulesOptions() => GetModulesOptions(GetContext()); -// -// -// -// public async Task RunAsync() -// { -// // LogInternal("Run app start"); -// // LogInternal("Build and init"); -// // var context = await BuildAppContextAsync(); -// -// // var enabledModules = GetEnabledModuleRegistrations(context).ToArray(); -// // foreach (var enabledModule in enabledModules) -// // { -// // var shouldContinue = await enabledModule.GetInstance().OnBeforeRunAsync(this, context, Args); -// // if (!shouldContinue) -// // { -// // return; -// // } -// // } -// -// // LogInternal("Check required modules"); -// // var modulesCheckSuccess = true; -// // foreach (var registration in enabledModules) -// // { -// // var result = -// // registration.CheckRequiredModules(context, -// // enabledModules.Select(r => r.Type).ToArray()); -// // if (!result.isSuccess) -// // { -// // foreach (var missingModule in result.missingModules) -// // { -// // LogInternal($"Required module {missingModule} for module {registration.Type} is not registered"); -// // } -// // -// // modulesCheckSuccess = false; -// // } -// // } -// -// // if (!modulesCheckSuccess) -// // { -// // LogInternal("Check required modules failed"); -// // return; -// // } -// -// // foreach (var enabledModule in enabledModules) -// // { -// // var shouldContinue = await enabledModule.GetInstance().OnAfterRunAsync(this, context, Args); -// // if (!shouldContinue) -// // { -// // return; -// // } -// // } -// -// //await DoRunAsync(); -// } -// -// protected abstract Task DoRunAsync(); -// -// protected abstract Task BuildAppContextAsync(); -// -// public abstract Task StopAsync(); -// -// // protected async Task InitAsync(IServiceProvider serviceProvider) -// // { -// // LogInternal("Build and init async start"); -// // using var scope = serviceProvider.CreateScope(); -// // var logger = scope.ServiceProvider.GetRequiredService>(); -// // logger.LogInformation("Init modules"); -// // // var registrations = GetEnabledModuleRegistrations(GetContext(scope.ServiceProvider)); -// // // var context = GetContext(scope.ServiceProvider); -// // // foreach (var configurationModule in registrations.Select(module => module.GetInstance()) -// // // .OfType()) -// // // { -// // // configurationModule.CheckConfiguration(context, scope.ServiceProvider); -// // // } -// // // -// // // foreach (var registration in registrations) -// // // { -// // // logger.LogInformation("Init module {Module}", registration.Type); -// // // await registration.InitAsync(context, scope.ServiceProvider); -// // // } -// // -// // LogInternal("Build and init async done"); -// // } -// -// protected virtual void LogInternal(string message) { } -// -// protected abstract bool CanAddModule(); -// -// // [PublicAPI] -// // protected void RegisterModule( -// // Action? configureOptions = null, -// // string? optionsKey = null) -// // where TModule : IApplicationModule, new() where TModuleOptions : BaseModuleOptions, new() -// // { -// // if (!CanAddModule()) -// // { -// // throw new InvalidOperationException("App host is already built. Can't add modules after it"); -// // } -// // -// // var instance = new TModule(); -// // if (!instance.AllowMultiple && HasModule()) -// // { -// // throw new InvalidOperationException($"Module {typeof(TModule)} already registered"); -// // } -// // -// // moduleRegistrations.Add( -// // new ApplicationModuleRegistration(instance, configureOptions, optionsKey)); -// // } -// -// // protected virtual void InitApplication() -// // { -// // } -// -// -// // [PublicAPI] -// // protected abstract IApplicationContext GetContext(); -// // -// // [PublicAPI] -// // protected abstract IApplicationContext GetContext(IServiceProvider serviceProvider); -// -// -// -// -// public Application AddModule() where TModule : BaseApplicationModule, new() -// -// { -// //RegisterModule(); -// return this; -// } -// -// public Application AddModule( -// Action configureOptions, -// string? optionsKey = null) -// where TModule : IApplicationModule, new() -// where TModuleOptions : BaseModuleOptions, new() -// { -// //RegisterModule(configureOptions, optionsKey); -// return this; -// } -// -// public Application AddModule( -// Action? configureOptions = null, -// string? optionsKey = null) -// where TModule : IApplicationModule, new() -// where TModuleOptions : BaseModuleOptions, new() => -// AddModule((_, moduleOptions) => -// { -// configureOptions?.Invoke(moduleOptions); -// }, optionsKey); -// } diff --git a/src/Sitko.Core.App/ApplicationBuilderFactory.cs b/src/Sitko.Core.App/ApplicationBuilderFactory.cs new file mode 100644 index 000000000..8b22b4d35 --- /dev/null +++ b/src/Sitko.Core.App/ApplicationBuilderFactory.cs @@ -0,0 +1,42 @@ +using System.Collections.Concurrent; + +namespace Sitko.Core.App; + +public static class ApplicationBuilderFactory +{ + private static readonly ConcurrentDictionary Builders = new(); + + public static TSitkoCoreApplicationBuilder + GetOrCreateApplicationBuilder( + TApplicationBuilder applicationBuilder, Func create) + where TSitkoCoreApplicationBuilder : ISitkoCoreApplicationBuilder where TApplicationBuilder : notnull + { + var appBuilder = Builders.GetOrAdd(applicationBuilder.GetHashCode(), _ => create(applicationBuilder)); + if (appBuilder is not TSitkoCoreApplicationBuilder typedBuilder) + { + throw new InvalidOperationException($"Application builder is not {typeof(TSitkoCoreApplicationBuilder)}"); + } + + return typedBuilder; + } + + + public static TSitkoCoreApplicationBuilder GetApplicationBuilder(TApplicationBuilder applicationBuilder) + where TSitkoCoreApplicationBuilder : ISitkoCoreApplicationBuilder where TApplicationBuilder : notnull + { + if (Builders.ContainsKey(applicationBuilder.GetHashCode())) + { + var builder = Builders[applicationBuilder.GetHashCode()]; + if (builder is TSitkoCoreApplicationBuilder typedBuilder) + { + return typedBuilder; + } + + throw new InvalidOperationException($"Application builder is not {typeof(TSitkoCoreApplicationBuilder)}"); + } + + throw new InvalidOperationException( + $"Application builder wasn't created for this HostBuilder. Call .AddSitkoCore*()"); + } +} diff --git a/src/Sitko.Core.App/BuilderApplicationContext.cs b/src/Sitko.Core.App/BuilderApplicationContext.cs index 077099245..2717ad806 100644 --- a/src/Sitko.Core.App/BuilderApplicationContext.cs +++ b/src/Sitko.Core.App/BuilderApplicationContext.cs @@ -10,13 +10,34 @@ namespace Sitko.Core.App; +public interface IApplicationEnvironment +{ + string EnvironmentName { get; } + bool IsDevelopment(); + bool IsProduction(); +} + +public class ServerApplicationEnvironment : IApplicationEnvironment +{ + private readonly IHostEnvironment hostEnvironment; + + public ServerApplicationEnvironment(IHostEnvironment hostEnvironment) => this.hostEnvironment = hostEnvironment; + + public string EnvironmentName => hostEnvironment.EnvironmentName; + public bool IsDevelopment() => hostEnvironment.IsDevelopment(); + + public bool IsProduction() => hostEnvironment.IsProduction(); +} + public class BuilderApplicationContext : IApplicationContext { - private readonly IHostEnvironment environment; + public static string OptionsKey => "Application"; + + private readonly IApplicationEnvironment environment; private ApplicationOptions? applicationOptions; - public BuilderApplicationContext(IConfiguration configuration, IHostEnvironment environment, + public BuilderApplicationContext(IConfiguration configuration, IApplicationEnvironment environment, IApplicationArgsProvider applicationArgsProvider) { this.environment = environment; @@ -54,7 +75,7 @@ private ApplicationOptions GetApplicationOptions() } applicationOptions = new ApplicationOptions(); - Configuration.Bind(SitkoCoreApplicationBuilder.OptionsKey, applicationOptions); + Configuration.Bind(OptionsKey, applicationOptions); if (string.IsNullOrEmpty(applicationOptions.Name)) { applicationOptions.Name = Assembly.GetEntryAssembly()?.GetName().Name ?? "App"; diff --git a/src/Sitko.Core.App/HostApplicationBuilderExtensions.cs b/src/Sitko.Core.App/HostApplicationBuilderExtensions.cs index 8420449f5..a83eb5f4e 100644 --- a/src/Sitko.Core.App/HostApplicationBuilderExtensions.cs +++ b/src/Sitko.Core.App/HostApplicationBuilderExtensions.cs @@ -1,16 +1,21 @@ -using System.Collections.Concurrent; using Microsoft.Extensions.Hosting; namespace Sitko.Core.App; public static class HostApplicationBuilderExtensions { - private static readonly ConcurrentDictionary Builders = new(); + public static ISitkoCoreApplicationBuilder + AddSitkoCore(this IHostApplicationBuilder builder) => AddSitkoCore(builder); - public static SitkoCoreApplicationBuilder - AddSitkoCore(this IHostApplicationBuilder builder) => + public static TSitkoCoreApplicationBuilder + AddSitkoCore(this IHostApplicationBuilder builder) + where TSitkoCoreApplicationBuilder : ISitkoCoreApplicationBuilder => + ApplicationBuilderFactory.GetApplicationBuilder(builder); + + public static ISitkoCoreServerApplicationBuilder AddSitkoCore(this HostApplicationBuilder builder) => builder.AddSitkoCore(Array.Empty()); - public static SitkoCoreApplicationBuilder AddSitkoCore(this IHostApplicationBuilder builder, string[] args) => - Builders.GetOrAdd(builder, _ => new SitkoCoreApplicationBuilder(builder, args)); + public static ISitkoCoreServerApplicationBuilder AddSitkoCore(this HostApplicationBuilder builder, string[] args) => + ApplicationBuilderFactory.GetOrCreateApplicationBuilder(builder, + applicationBuilder => new SitkoCoreServerApplicationBuilder(applicationBuilder, args)); } diff --git a/src/Sitko.Core.App/HostedApplication.cs b/src/Sitko.Core.App/HostedApplication.cs deleted file mode 100644 index 9e6ed1685..000000000 --- a/src/Sitko.Core.App/HostedApplication.cs +++ /dev/null @@ -1,248 +0,0 @@ -// using Microsoft.Extensions.Configuration; -// using Microsoft.Extensions.Hosting; -// -// namespace Sitko.Core.App; -// -// public abstract class HostedApplication : Application -// { -// // private IHost? appHost; -// -// protected HostedApplication(string[] args) : base(args) -// { -// // Console.OutputEncoding = Encoding.UTF8; -// // var loggerConfiguration = new LoggerConfiguration(); -// // loggerConfiguration -// // .WriteTo.Console(outputTemplate: ApplicationOptions.BaseConsoleLogFormat, -// // formatProvider: CultureInfo.InvariantCulture, -// // restrictedToMinimumLevel: LogEventLevel.Debug); -// // InternalLogger = new SerilogLoggerFactory(loggerConfiguration.CreateLogger()).CreateLogger(); -// } -// -// /*protected ILogger InternalLogger { get; } -// -// protected virtual IHostBuilder CreateHostBuilderBase(string[] hostBuilderArgs) => -// Host.CreateDefaultBuilder(hostBuilderArgs); -// -// private IHostBuilder CreateHostBuilder(string[] hostBuilderArgs) -// { -// var builder = CreateHostBuilderBase(hostBuilderArgs); -// ConfigureHostBuilder(builder); -// return builder; -// } -// -// protected virtual void ConfigureHostBuilder(IHostBuilder builder) -// { -// builder.ConfigureHostConfiguration(ConfigureHostConfiguration); -// builder.ConfigureAppConfiguration(ConfigureAppConfiguration); -// } -// -// protected override void LogInternal(string message) => -// InternalLogger.LogInformation("Check log: {Message}", message);*/ -// -// // protected IHost CreateAppHost(Action? configure = null) -// // { -// // LogInternal("Create app host start"); -// // -// // if (appHost is not null) -// // { -// // LogInternal("App host is already built"); -// // -// // return appHost; -// // } -// // -// // LogInternal("Configure host builder"); -// // -// // var hostBuilder = ConfigureHostBuilder(configure); -// // -// // LogInternal("Build host"); -// // var newHost = hostBuilder.Build(); -// // -// // appHost = newHost; -// // LogInternal("Create app host done"); -// // return appHost; -// // } -// -// // protected IApplicationContext GetContext(IHostEnvironment environment, IConfiguration configuration) => -// // new HostedApplicationContext(this, configuration, environment); -// -// // protected IHostBuilder ConfigureHostBuilder(Action? configure = null) -// // { -// // // LogInternal("Configure host builder start"); -// // // -// // // LogInternal("Create tmp host builder"); -// // // -// // // var startEnvironment = new HostingEnvironment -// // // { -// // // ApplicationName = GetType().Assembly.FullName!, EnvironmentName = EnvHelper.GetEnvironmentName() -// // // }; -// // // -// // // var configBuilder = new ConfigurationBuilder() -// // // .AddEnvironmentVariables() -// // // .AddEnvironmentVariables("DOTNET_") -// // // .AddEnvironmentVariables("ASPNETCORE_") -// // // .AddJsonFile("appsettings.json", true, false) -// // // .AddJsonFile($"appsettings.{startEnvironment.EnvironmentName}.json", true, false); -// // // var startApplicationContext = GetContext(startEnvironment, configBuilder.Build()); -// // // ConfigureConfiguration(startApplicationContext, configBuilder); -// // -// // //LogInternal("Init application"); -// // -// // //InitApplication(); -// // -// // // LogInternal("Create main host builder"); -// // // var hostBuilder = CreateHostBuilder(Args) -// // // .UseDefaultServiceProvider(options => -// // // { -// // // options.ValidateOnBuild = true; -// // // options.ValidateScopes = true; -// // // }); -// // -// // //LogInternal("Configure host builder in modules"); -// // //var bootConfiguration = configBuilder.Build(); -// // // var bootEnvironment = new HostingEnvironment -// // // { -// // // ApplicationName = bootConfiguration[HostDefaults.ApplicationKey] ?? "", -// // // EnvironmentName = bootConfiguration[HostDefaults.EnvironmentKey] ?? Environments.Production -// // // }; -// // //var bootApplicationContext = GetContext(bootEnvironment, bootConfiguration); -// // -// // // foreach (var moduleRegistration in GetEnabledModuleRegistrations(bootApplicationContext)) -// // // { -// // // moduleRegistration.ConfigureHostBuilder(bootApplicationContext, hostBuilder); -// // // } -// // -// // //LogInternal("Configure host builder"); -// // // hostBuilder.ConfigureAppConfiguration((_, builder) => -// // // { -// // // //ConfigureConfiguration(bootApplicationContext, builder); -// // // }) -// // // // .ConfigureServices((_, services) => -// // // // { -// // // // //RegisterApplicationServices(bootApplicationContext, services); -// // // // //services.AddHostedService(); -// // // // }) -// // // .ConfigureLogging((builderContext, builder) => -// // // { -// // // // LogInternal("Configure logging"); -// // // // var runtimeContext = GetContext(builderContext.HostingEnvironment, builderContext.Configuration); -// // // // LoggingExtensions.ConfigureSerilog(runtimeContext, builder, -// // // // configuration => -// // // // { -// // // // configuration = configuration.Enrich.WithMachineName(); -// // // // if (runtimeContext.Options.EnableConsoleLogging == true) -// // // // { -// // // // configuration = configuration.WriteTo.Console( -// // // // outputTemplate: runtimeContext.Options.ConsoleLogFormat, -// // // // formatProvider: CultureInfo.InvariantCulture); -// // // // } -// // // // -// // // // return ConfigureLogging(runtimeContext, configuration); -// // // // }); -// // // }); -// // //configure?.Invoke(hostBuilder); -// // //PostConfigureHostBuilder(bootApplicationContext, hostBuilder); -// // // foreach (var moduleRegistration in GetEnabledModuleRegistrations(bootApplicationContext)) -// // // { -// // // moduleRegistration.PostConfigureHostBuilder(bootApplicationContext, hostBuilder); -// // // } -// // LogInternal("Create host builder done"); -// // return hostBuilder; -// // } -// -// // protected virtual void PostConfigureHostBuilder(IApplicationContext applicationContext, IHostBuilder hostBuilder) -// // { -// // } -// // -// // protected override async ValueTask DisposeAsync(bool disposing) -// // { -// // await base.DisposeAsync(disposing); -// // if (disposing) -// // { -// // appHost?.Dispose(); -// // } -// // } -// -// // public async Task ExecuteAsync(Func command) -// // { -// // var currentHost = await GetOrCreateHostAsync(builder => builder.UseConsoleLifetime()); -// // -// // var serviceProvider = currentHost.Services; -// // -// // try -// // { -// // using var scope = serviceProvider.CreateScope(); -// // await command(scope.ServiceProvider); -// // } -// // catch (Exception ex) -// // { -// // var logger = serviceProvider.GetRequiredService>(); -// // logger.LogError(ex, "Error: {ErrorText}", ex.ToString()); -// // } -// // } -// -// -// //public override Task StopAsync() => CreateAppHost().StopAsync(); -// // protected override bool CanAddModule() => appHost is null; -// //public IHostBuilder GetHostBuilder() => ConfigureHostBuilder(); -// -// // protected override IApplicationContext GetContext() => appHost is not null -// // ? GetContext(appHost.Services) -// // : throw new InvalidOperationException("App host is not built yet"); -// -// // protected async Task GetOrCreateHostAsync(Action? configure = null) -// // { -// // if (appHost is not null) -// // { -// // return appHost; -// // } -// // -// // appHost = CreateAppHost(configure); -// // -// // await InitAsync(appHost.Services); -// // -// // return appHost; -// // } -// -// // protected override async Task BuildAppContextAsync() -// // { -// // var currentHost = await GetOrCreateHostAsync(); -// // return GetContext(currentHost.Services); -// // } -// // -// // public async Task StartAsync() -// // { -// // var currentHost = await GetOrCreateHostAsync(); -// // await currentHost.StartAsync(); -// // return currentHost; -// // } -// // -// // protected override async Task DoRunAsync() -// // { -// // var currentHost = await GetOrCreateHostAsync(); -// // await currentHost.RunAsync(); -// // } -// // -// // public async Task GetServiceProviderAsync() => (await GetOrCreateHostAsync()).Services; -// -// // protected override IApplicationContext GetContext(IServiceProvider serviceProvider) => GetContext( -// // serviceProvider.GetRequiredService(), -// // serviceProvider.GetRequiredService()); -// } -// -// // public class HostedApplicationContext : BaseApplicationContext -// // { -// // private readonly IHostEnvironment environment; -// // -// // public HostedApplicationContext(Application application, IConfiguration configuration, IHostEnvironment environment) -// // : base(application, -// // configuration) => -// // this.environment = environment; -// // -// // public override string AspNetEnvironmentName => environment.EnvironmentName; -// // public override bool IsDevelopment() => environment.IsDevelopment(); -// // -// // public override bool IsProduction() => environment.IsProduction(); -// // -// // protected override void ConfigureApplicationOptions(ApplicationOptions options) => -// // options.EnableConsoleLogging ??= environment.IsDevelopment(); -// // } diff --git a/src/Sitko.Core.App/ISitkoCoreApplicationBuilder.cs b/src/Sitko.Core.App/ISitkoCoreApplicationBuilder.cs new file mode 100644 index 000000000..4ab2c1550 --- /dev/null +++ b/src/Sitko.Core.App/ISitkoCoreApplicationBuilder.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.DependencyInjection; +using Serilog; +using Serilog.Events; + +namespace Sitko.Core.App; + +public interface ISitkoCoreApplicationBuilder +{ + ISitkoCoreApplicationBuilder AddModule() where TModule : BaseApplicationModule, new(); + + ISitkoCoreApplicationBuilder AddModule( + Action configureOptions, + string? optionsKey = null) + where TModule : IApplicationModule, new() + where TModuleOptions : BaseModuleOptions, new(); + + ISitkoCoreApplicationBuilder AddModule( + Action? configureOptions = null, + string? optionsKey = null) + where TModule : IApplicationModule, new() + where TModuleOptions : BaseModuleOptions, new(); + + bool HasModule() where TModule : IApplicationModule; + + ISitkoCoreApplicationBuilder ConfigureLogLevel(string source, LogEventLevel level); + + ISitkoCoreApplicationBuilder ConfigureLogging( + Func configure); + + ISitkoCoreApplicationBuilder ConfigureServices(Action configure); +} diff --git a/src/Sitko.Core.App/ISitkoCoreServerApplicationBuilder.cs b/src/Sitko.Core.App/ISitkoCoreServerApplicationBuilder.cs new file mode 100644 index 000000000..7c009c875 --- /dev/null +++ b/src/Sitko.Core.App/ISitkoCoreServerApplicationBuilder.cs @@ -0,0 +1,5 @@ +namespace Sitko.Core.App; + +public interface ISitkoCoreServerApplicationBuilder : ISitkoCoreApplicationBuilder +{ +} diff --git a/src/Sitko.Core.App/Localization/ApplicationExtensions.cs b/src/Sitko.Core.App/Localization/ApplicationExtensions.cs index f9b14debd..320fb846e 100644 --- a/src/Sitko.Core.App/Localization/ApplicationExtensions.cs +++ b/src/Sitko.Core.App/Localization/ApplicationExtensions.cs @@ -21,12 +21,12 @@ public static IHostApplicationBuilder AddJsonLocalization(this IHostApplicationB return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddJsonLocalization(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddJsonLocalization(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddJsonLocalization(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddJsonLocalization(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.App/SitkoCoreApplicationBuilder.cs b/src/Sitko.Core.App/SitkoCoreBaseApplicationBuilder.cs similarity index 57% rename from src/Sitko.Core.App/SitkoCoreApplicationBuilder.cs rename to src/Sitko.Core.App/SitkoCoreBaseApplicationBuilder.cs index 438b8977d..0166109cf 100644 --- a/src/Sitko.Core.App/SitkoCoreApplicationBuilder.cs +++ b/src/Sitko.Core.App/SitkoCoreBaseApplicationBuilder.cs @@ -1,5 +1,6 @@ using System.Globalization; using System.Text; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -13,26 +14,24 @@ namespace Sitko.Core.App; -public class SitkoCoreApplicationBuilder +public abstract class SitkoCoreBaseApplicationBuilder : ISitkoCoreApplicationBuilder { - public static string OptionsKey => "Application"; - protected IApplicationContext BootApplicationContext { get; } - protected IHostApplicationBuilder Builder { get; } - - private readonly List moduleRegistrations = - new(); - + private readonly List moduleRegistrations = new(); private readonly SerilogConfigurator serilogConfigurator = new(); - public SitkoCoreApplicationBuilder(IHostApplicationBuilder builder, string[] args) + protected SitkoCoreBaseApplicationBuilder(string[] args, IServiceCollection services, + IConfigurationBuilder configuration, IApplicationEnvironment environment, ILoggingBuilder logging) { - Builder = builder; - var bootConfig = builder.Configuration.Build(); + Services = services; + Configuration = configuration; + Environment = environment; + Logging = logging; var argsProvider = new ApplicationArgsProvider(args); - BootApplicationContext = new BuilderApplicationContext(bootConfig, builder.Environment, argsProvider); + var bootConfig = Configuration.Build(); + BootApplicationContext = new BuilderApplicationContext(bootConfig, Environment, argsProvider); // configure logging - builder.Configuration.Add(new SerilogDynamicConfigurationSource()); + Configuration.Add(new SerilogDynamicConfigurationSource()); var tmpLoggerConfiguration = new LoggerConfiguration(); tmpLoggerConfiguration = ConfigureDefautLogger(tmpLoggerConfiguration); if (BootApplicationContext.Options.EnableConsoleLogging != true) @@ -47,54 +46,56 @@ public SitkoCoreApplicationBuilder(IHostApplicationBuilder builder, string[] arg Log.Logger = tmpLogger; // set default logger until host is started Console.OutputEncoding = Encoding.UTF8; InternalLogger = new SerilogLoggerFactory(tmpLogger) - .CreateLogger(); + .CreateLogger(); AddModule(); - builder.Logging.ClearProviders(); - builder.Logging.AddSerilog(); + Logging.ClearProviders(); + Logging.AddSerilog(); + serilogConfigurator.Configure(ConfigureDefautLogger); + + Services.AddSingleton(argsProvider); + Services.AddSingleton(environment); + Services.AddSingleton(serilogConfigurator); + Services.AddSingleton(); + Services.AddTransient(); + Services.AddFluentValidationExtensions(); + Services.AddTransient(typeof(ILocalizationProvider<>), typeof(LocalizationProvider<>)); + Services.AddHostedService(); // только Hosted? Проверить для Wasm + } - serilogConfigurator.Configure(configuration => ConfigureDefautLogger(configuration)); + protected ILogger InternalLogger { get; } + protected IApplicationContext BootApplicationContext { get; } + protected IServiceCollection Services { get; } + protected IConfigurationBuilder Configuration { get; } + protected IApplicationEnvironment Environment { get; } + protected ILoggingBuilder Logging { get; } - builder.Services.AddSingleton(argsProvider); - builder.Services.AddSingleton(serilogConfigurator); - builder.Services.AddSingleton(); - builder.Services.AddTransient(); - builder.Services.AddFluentValidationExtensions(); - builder.Services.AddTransient(typeof(ILocalizationProvider<>), typeof(LocalizationProvider<>)); - builder.Services.AddHostedService(); // только Hosted? Проверить для Wasm + public ISitkoCoreApplicationBuilder ConfigureLogLevel(string source, LogEventLevel level) + { + serilogConfigurator.ConfigureLogLevel(source, level); + return this; } - protected ILogger InternalLogger { get; } - - protected LoggerConfiguration ConfigureDefautLogger(LoggerConfiguration loggerConfiguration) + public ISitkoCoreApplicationBuilder ConfigureLogging( + Func configure) { - loggerConfiguration = loggerConfiguration.ReadFrom.Configuration(BootApplicationContext.Configuration); - loggerConfiguration = loggerConfiguration - .Enrich.FromLogContext() - .Enrich.WithProperty("App", BootApplicationContext.Name) - .Enrich.WithProperty("AppVersion", BootApplicationContext.Version) - .Enrich.WithProperty("AppEnvironment", BootApplicationContext.Environment) - .Enrich.WithMachineName(); - if (BootApplicationContext.Options.EnableConsoleLogging == true) - { - loggerConfiguration = loggerConfiguration.WriteTo.Console( - outputTemplate: BootApplicationContext.Options.ConsoleLogFormat, - formatProvider: CultureInfo.InvariantCulture); - } - - return loggerConfiguration; + serilogConfigurator.ConfigureLogging(configure); + return this; } - protected void LogInternal(string message) => - InternalLogger.LogInformation("Check log: {Message}", message); + public ISitkoCoreApplicationBuilder ConfigureServices(Action configure) + { + configure(Services); + return this; + } - public SitkoCoreApplicationBuilder AddModule() where TModule : BaseApplicationModule, new() + public ISitkoCoreApplicationBuilder AddModule() where TModule : BaseApplicationModule, new() { RegisterModule(); return this; } - public SitkoCoreApplicationBuilder AddModule( + public ISitkoCoreApplicationBuilder AddModule( Action configureOptions, string? optionsKey = null) where TModule : IApplicationModule, new() @@ -104,7 +105,7 @@ public SitkoCoreApplicationBuilder AddModule( return this; } - public SitkoCoreApplicationBuilder AddModule( + public ISitkoCoreApplicationBuilder AddModule( Action? configureOptions = null, string? optionsKey = null) where TModule : IApplicationModule, new() @@ -132,45 +133,49 @@ private void RegisterModule( new ApplicationModuleRegistration(instance, configureOptions, optionsKey); if (registration.IsEnabled(BootApplicationContext)) { - if (typeof(TModule).IsAssignableTo(typeof(IHostBuilderModule))) - { - ConfigureHostBuilder(registration); - } - - registration.ConfigureAppConfiguration(BootApplicationContext, Builder.Configuration); - registration.ConfigureOptions(BootApplicationContext, Builder.Services); - registration.ConfigureServices(BootApplicationContext, Builder.Services); - - if (typeof(TModule).IsAssignableTo(typeof(IHostBuilderModule))) - { - registration.PostConfigureHostBuilder(BootApplicationContext, Builder); - } + BeforeModuleRegistration(BootApplicationContext, registration); + + registration.ConfigureAppConfiguration(BootApplicationContext, Configuration); + registration.ConfigureOptions(BootApplicationContext, Services); + registration.ConfigureServices(BootApplicationContext, Services); + + AfterModuleRegistration(BootApplicationContext, registration); } moduleRegistrations.Add(registration); - Builder.Services.AddSingleton(registration); + Services.AddSingleton(registration); } - protected virtual void ConfigureHostBuilder(ApplicationModuleRegistration registration) - where TModule : IApplicationModule, new() where TModuleOptions : BaseModuleOptions, new() => - registration.ConfigureHostBuilder(BootApplicationContext, Builder); - - public SitkoCoreApplicationBuilder ConfigureLogLevel(string source, LogEventLevel level) + protected virtual void BeforeModuleRegistration(IApplicationContext applicationContext, + ApplicationModuleRegistration moduleRegistration) where TModule : IApplicationModule, new() + where TModuleOptions : BaseModuleOptions, new() { - serilogConfigurator.ConfigureLogLevel(source, level); - return this; } - public SitkoCoreApplicationBuilder ConfigureLogging( - Func configure) + protected virtual void AfterModuleRegistration(IApplicationContext applicationContext, + ApplicationModuleRegistration moduleRegistration) where TModule : IApplicationModule, new() + where TModuleOptions : BaseModuleOptions, new() { - serilogConfigurator.ConfigureLogging(configure); - return this; } - public SitkoCoreApplicationBuilder ConfigureServices(Action configure) + protected virtual LoggerConfiguration ConfigureDefautLogger(LoggerConfiguration loggerConfiguration) { - configure(Builder.Services); - return this; + loggerConfiguration = loggerConfiguration.ReadFrom.Configuration(BootApplicationContext.Configuration); + loggerConfiguration = loggerConfiguration + .Enrich.FromLogContext() + .Enrich.WithProperty("App", BootApplicationContext.Name) + .Enrich.WithProperty("AppVersion", BootApplicationContext.Version) + .Enrich.WithProperty("AppEnvironment", BootApplicationContext.Environment) + .Enrich.WithMachineName(); + if (BootApplicationContext.Options.EnableConsoleLogging == true) + { + loggerConfiguration = loggerConfiguration.WriteTo.Console( + outputTemplate: BootApplicationContext.Options.ConsoleLogFormat, + formatProvider: CultureInfo.InvariantCulture); + } + + return loggerConfiguration; } + + protected void LogInternal(string message) => InternalLogger.LogInformation("Check log: {Message}", message); } diff --git a/src/Sitko.Core.App/SitkoCoreServerApplicationBuilder.cs b/src/Sitko.Core.App/SitkoCoreServerApplicationBuilder.cs new file mode 100644 index 000000000..35b5fd74e --- /dev/null +++ b/src/Sitko.Core.App/SitkoCoreServerApplicationBuilder.cs @@ -0,0 +1,37 @@ +using Microsoft.Extensions.Hosting; + +namespace Sitko.Core.App; + +public class SitkoCoreServerApplicationBuilder : SitkoCoreBaseApplicationBuilder, ISitkoCoreServerApplicationBuilder +{ + private readonly IHostApplicationBuilder applicationBuilder; + + public SitkoCoreServerApplicationBuilder(IHostApplicationBuilder applicationBuilder, string[] args) : base(args, + applicationBuilder.Services, applicationBuilder.Configuration, new ServerApplicationEnvironment(applicationBuilder.Environment), + applicationBuilder.Logging) => + this.applicationBuilder = applicationBuilder; + + protected override void BeforeModuleRegistration(IApplicationContext applicationContext, + ApplicationModuleRegistration moduleRegistration) + { + base.BeforeModuleRegistration(applicationContext, moduleRegistration); + if (typeof(TModule).IsAssignableTo(typeof(IHostBuilderModule))) + { + ConfigureHostBuilder(moduleRegistration); + } + } + + protected virtual void ConfigureHostBuilder(ApplicationModuleRegistration registration) + where TModule : IApplicationModule, new() where TModuleOptions : BaseModuleOptions, new() => + registration.ConfigureHostBuilder(BootApplicationContext, applicationBuilder); + + protected override void AfterModuleRegistration(IApplicationContext applicationContext, + ApplicationModuleRegistration moduleRegistration) + { + base.AfterModuleRegistration(applicationContext, moduleRegistration); + if (typeof(TModule).IsAssignableTo(typeof(IHostBuilderModule))) + { + moduleRegistration.PostConfigureHostBuilder(BootApplicationContext, applicationBuilder); + } + } +} diff --git a/src/Sitko.Core.Auth.Basic/ApplicationExtensions.cs b/src/Sitko.Core.Auth.Basic/ApplicationExtensions.cs index 53a676c03..2a479c414 100644 --- a/src/Sitko.Core.Auth.Basic/ApplicationExtensions.cs +++ b/src/Sitko.Core.Auth.Basic/ApplicationExtensions.cs @@ -21,11 +21,11 @@ public static IHostApplicationBuilder AddBasicAuth(this IHostApplicationBuilder return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddBasicAuth(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddBasicAuth(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddBasicAuth(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddBasicAuth(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Auth.Google/ApplicationExtensions.cs b/src/Sitko.Core.Auth.Google/ApplicationExtensions.cs index e047e4ed7..6ea6881cf 100644 --- a/src/Sitko.Core.Auth.Google/ApplicationExtensions.cs +++ b/src/Sitko.Core.Auth.Google/ApplicationExtensions.cs @@ -21,11 +21,11 @@ public static IHostApplicationBuilder AddGoogleAuth(this IHostApplicationBuilder return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddGoogleAuth(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddGoogleAuth(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddGoogleAuth(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddGoogleAuth(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Auth.IdentityServer/ApplicationExtensions.cs b/src/Sitko.Core.Auth.IdentityServer/ApplicationExtensions.cs index cd91bc83f..e4dc77a6d 100644 --- a/src/Sitko.Core.Auth.IdentityServer/ApplicationExtensions.cs +++ b/src/Sitko.Core.Auth.IdentityServer/ApplicationExtensions.cs @@ -37,25 +37,25 @@ public static IHostApplicationBuilder AddOidcIdentityServer(this IHostApplicatio return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddJwtIdentityServer(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddJwtIdentityServer(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder .AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddJwtIdentityServer(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddJwtIdentityServer(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder .AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddOidcIdentityServer(this SitkoCoreApplicationBuilder application, + public static ISitkoCoreApplicationBuilder AddOidcIdentityServer(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => - application.AddModule(configure, + applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddOidcIdentityServer(this SitkoCoreApplicationBuilder application, + public static ISitkoCoreApplicationBuilder AddOidcIdentityServer(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => - application.AddModule(configure, + applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Automapper/ApplicationExtensions.cs b/src/Sitko.Core.Automapper/ApplicationExtensions.cs index 8e14b53ac..1c92c8e74 100644 --- a/src/Sitko.Core.Automapper/ApplicationExtensions.cs +++ b/src/Sitko.Core.Automapper/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddAutoMapper(this IHostApplicationBuilder return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddAutoMapper(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddAutoMapper(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddAutoMapper(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddAutoMapper(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Blazor.AntDesign.Server/ApplicationExtensions.cs b/src/Sitko.Core.Blazor.AntDesign.Server/ApplicationExtensions.cs index 682bc9095..fa06596e0 100644 --- a/src/Sitko.Core.Blazor.AntDesign.Server/ApplicationExtensions.cs +++ b/src/Sitko.Core.Blazor.AntDesign.Server/ApplicationExtensions.cs @@ -11,11 +11,14 @@ public static class ApplicationExtensions { public static WebApplicationBuilder AddAntBlazorServer(this WebApplicationBuilder webApplicationBuilder) { - webApplicationBuilder.AddSitkoCore().AddAntBlazorServer(); + webApplicationBuilder.AddSitkoCore().AddAntBlazorServer(); return webApplicationBuilder; } - public static SitkoCoreApplicationBuilder - AddAntBlazorServer(this SitkoCoreApplicationBuilder webApplicationBuilder) => - webApplicationBuilder.AddBlazorServer().AddBlazorFileUpload(); + public static ISitkoCoreBlazorServerApplicationBuilder + AddAntBlazorServer(this ISitkoCoreBlazorServerApplicationBuilder webApplicationBuilder) + { + webApplicationBuilder.AddBlazorFileUpload(); + return webApplicationBuilder; + } } diff --git a/src/Sitko.Core.Blazor.FileUpload/ApplicationExtensions.cs b/src/Sitko.Core.Blazor.FileUpload/ApplicationExtensions.cs index aa2cb34a3..0253d928a 100644 --- a/src/Sitko.Core.Blazor.FileUpload/ApplicationExtensions.cs +++ b/src/Sitko.Core.Blazor.FileUpload/ApplicationExtensions.cs @@ -9,11 +9,14 @@ public static class ApplicationExtensions { public static IHostApplicationBuilder AddBlazorFileUpload(this IHostApplicationBuilder hostApplicationBuilder) { - hostApplicationBuilder.AddSitkoCore().AddBlazorFileUpload(); + hostApplicationBuilder.AddSitkoCore().AddBlazorFileUpload(); return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddBlazorFileUpload(this SitkoCoreApplicationBuilder applicationBuilder) => + public static ISitkoCoreBlazorApplicationBuilder AddBlazorFileUpload(this ISitkoCoreBlazorApplicationBuilder applicationBuilder) + { applicationBuilder.AddModule(); + return applicationBuilder; + } } diff --git a/src/Sitko.Core.Blazor.MudBlazor.Server/ApplicationExtensions.cs b/src/Sitko.Core.Blazor.MudBlazor.Server/ApplicationExtensions.cs index e56b4c078..bccb02f58 100644 --- a/src/Sitko.Core.Blazor.MudBlazor.Server/ApplicationExtensions.cs +++ b/src/Sitko.Core.Blazor.MudBlazor.Server/ApplicationExtensions.cs @@ -11,11 +11,11 @@ public static class ApplicationExtensions { public static WebApplicationBuilder AddMudBlazorServer(this WebApplicationBuilder webApplicationBuilder) { - webApplicationBuilder.AddSitkoCore().AddMudBlazorServer(); + webApplicationBuilder.AddSitkoCore().AddMudBlazorServer(); return webApplicationBuilder; } - public static SitkoCoreApplicationBuilder - AddMudBlazorServer(this SitkoCoreApplicationBuilder webApplicationBuilder) => - webApplicationBuilder.AddBlazorServer().AddMudBlazor(); + public static ISitkoCoreBlazorApplicationBuilder + AddMudBlazorServer(this ISitkoCoreBlazorServerApplicationBuilder webApplicationBuilder) => + webApplicationBuilder.AddMudBlazor(); } diff --git a/src/Sitko.Core.Blazor.MudBlazor/ApplicationExtensions.cs b/src/Sitko.Core.Blazor.MudBlazor/ApplicationExtensions.cs index a5694728d..82f7602c7 100644 --- a/src/Sitko.Core.Blazor.MudBlazor/ApplicationExtensions.cs +++ b/src/Sitko.Core.Blazor.MudBlazor/ApplicationExtensions.cs @@ -13,11 +13,12 @@ public static class ApplicationExtensions { public static IHostApplicationBuilder AddMudBlazor(this IHostApplicationBuilder hostApplicationBuilder) { - hostApplicationBuilder.AddSitkoCore().AddMudBlazor(); + hostApplicationBuilder.AddSitkoCore().AddMudBlazor(); return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddMudBlazor(this SitkoCoreApplicationBuilder applicationBuilder) => + public static ISitkoCoreBlazorApplicationBuilder AddMudBlazor(this ISitkoCoreBlazorApplicationBuilder applicationBuilder) + { applicationBuilder.ConfigureServices(services => { services.AddMudServices(); @@ -27,4 +28,7 @@ public static SitkoCoreApplicationBuilder AddMudBlazor(this SitkoCoreApplication options.AddDefaultResource(typeof(ApplicationExtensions)); }); }); + + return applicationBuilder; + } } diff --git a/src/Sitko.Core.Blazor.Server/BlazorApplication.cs b/src/Sitko.Core.Blazor.Server/BlazorApplication.cs index a760d5ddf..eb9d286fe 100644 --- a/src/Sitko.Core.Blazor.Server/BlazorApplication.cs +++ b/src/Sitko.Core.Blazor.Server/BlazorApplication.cs @@ -6,22 +6,29 @@ namespace Sitko.Core.Blazor.Server; -[PublicAPI] -public static class ApplicationExtensions +public interface ISitkoCoreBlazorServerApplicationBuilder : ISitkoCoreBlazorApplicationBuilder, ISitkoCoreServerApplicationBuilder { - public static WebApplicationBuilder AddBlazorServer(this WebApplicationBuilder webApplicationBuilder) - { - webApplicationBuilder.AddSitkoCore().AddBlazorServer(); - return webApplicationBuilder; - } +} - public static SitkoCoreApplicationBuilder AddBlazorServer(this SitkoCoreApplicationBuilder webApplicationBuilder) +public class SitkoCoreBlazorServerApplicationBuilder : SitkoCoreWebApplicationBuilder, + ISitkoCoreBlazorServerApplicationBuilder +{ + public SitkoCoreBlazorServerApplicationBuilder(WebApplicationBuilder builder, string[] args) : base(builder, args) { - webApplicationBuilder.AddPersistentState(); - webApplicationBuilder.ConfigureServices(collection => - { - collection.AddScriptInjector(); - }); - return webApplicationBuilder; + this.AddPersistentState(); + builder.Services.AddScriptInjector(); } } + +[PublicAPI] +public static class ApplicationExtensions +{ + public static ISitkoCoreBlazorServerApplicationBuilder AddBlazorServer( + this WebApplicationBuilder webApplicationBuilder) => + webApplicationBuilder.AddBlazorServer(Array.Empty()); + + public static ISitkoCoreBlazorServerApplicationBuilder AddBlazorServer( + this WebApplicationBuilder webApplicationBuilder, string[] args) => + ApplicationBuilderFactory.GetOrCreateApplicationBuilder(webApplicationBuilder, + applicationBuilder => new SitkoCoreBlazorServerApplicationBuilder(applicationBuilder, args)); +} diff --git a/src/Sitko.Core.Blazor.Wasm/WasmApplication.cs b/src/Sitko.Core.Blazor.Wasm/WasmApplication.cs index e033113f1..741ea6ad7 100644 --- a/src/Sitko.Core.Blazor.Wasm/WasmApplication.cs +++ b/src/Sitko.Core.Blazor.Wasm/WasmApplication.cs @@ -65,15 +65,9 @@ // var applicationContext = GetContext(hostBuilder.HostEnvironment, hostBuilder.Configuration); // var enabledModuleRegistrations = GetEnabledModuleRegistrations(applicationContext); // // App configuration -// ConfigureConfiguration(applicationContext, hostBuilder.Configuration); -// // App services -// RegisterApplicationServices(applicationContext, hostBuilder.Services); -// hostBuilder.Services.AddScriptInjector(); -// hostBuilder.Services.AddScoped(); -// hostBuilder.Services.Configure(options => -// { -// options.AddDefaultResource(typeof(BaseForm)); -// }); + + + // // Logging // LogInternal("Configure logging"); // LoggingExtensions.ConfigureSerilog(applicationContext, hostBuilder.Logging, diff --git a/src/Sitko.Core.Blazor.Wasm/WebAssemblyHostBuilderExtensions.cs b/src/Sitko.Core.Blazor.Wasm/WebAssemblyHostBuilderExtensions.cs new file mode 100644 index 000000000..9e711f081 --- /dev/null +++ b/src/Sitko.Core.Blazor.Wasm/WebAssemblyHostBuilderExtensions.cs @@ -0,0 +1,63 @@ +using System.Globalization; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.JSInterop; +using Serilog; +using Sitko.Blazor.ScriptInjector; +using Sitko.Core.App; +using Sitko.Core.App.Localization; +using Sitko.Core.Blazor.Components; +using Sitko.Core.Blazor.Forms; + +namespace Sitko.Core.Blazor.Wasm; + +public interface ISitkoCoreBlazorWasmApplicationBuilder : ISitkoCoreBlazorApplicationBuilder +{ +} + +public class WasmApplicationEnvironment : IApplicationEnvironment +{ + private readonly IWebAssemblyHostEnvironment builderHostEnvironment; + + public WasmApplicationEnvironment(IWebAssemblyHostEnvironment builderHostEnvironment) => + this.builderHostEnvironment = builderHostEnvironment; + + public string EnvironmentName => builderHostEnvironment.Environment; + public bool IsDevelopment() => builderHostEnvironment.IsDevelopment(); + + public bool IsProduction() => builderHostEnvironment.IsProduction(); +} + +public class SitkoCoreBlazorWasmApplicationBuilder : SitkoCoreBaseApplicationBuilder, + ISitkoCoreBlazorWasmApplicationBuilder +{ + public SitkoCoreBlazorWasmApplicationBuilder(WebAssemblyHostBuilder builder, string[] args) : base(args, + builder.Services, builder.Configuration, new WasmApplicationEnvironment(builder.HostEnvironment), + builder.Logging) + { + builder.Services.AddScriptInjector(); + builder.Services.AddScoped(); + builder.Services.Configure(options => + { + options.AddDefaultResource(typeof(BaseForm)); + }); + } + + protected override LoggerConfiguration ConfigureDefautLogger(LoggerConfiguration loggerConfiguration) + { + base.ConfigureDefautLogger(loggerConfiguration); + return loggerConfiguration.WriteTo.BrowserConsole( + outputTemplate: BootApplicationContext.Options.ConsoleLogFormat, + formatProvider: CultureInfo.InvariantCulture); + } +} + +public static class WebAssemblyHostBuilderExtensions +{ + public static ISitkoCoreBlazorApplicationBuilder AddSitkoCore(this WebAssemblyHostBuilder builder) => + builder.AddSitkoCore(Array.Empty()); + + public static ISitkoCoreBlazorApplicationBuilder AddSitkoCore(this WebAssemblyHostBuilder builder, string[] args) => + ApplicationBuilderFactory.GetOrCreateApplicationBuilder(builder, + applicationBuilder => new SitkoCoreBlazorWasmApplicationBuilder(applicationBuilder, args)); +} diff --git a/src/Sitko.Core.Blazor/ApplicationExtensions.cs b/src/Sitko.Core.Blazor/ApplicationExtensions.cs index 013578070..628e71733 100644 --- a/src/Sitko.Core.Blazor/ApplicationExtensions.cs +++ b/src/Sitko.Core.Blazor/ApplicationExtensions.cs @@ -6,6 +6,10 @@ namespace Sitko.Core.Blazor; +public interface ISitkoCoreBlazorApplicationBuilder : ISitkoCoreApplicationBuilder +{ +} + [PublicAPI] public static class ApplicationExtensions { @@ -21,13 +25,14 @@ public static IHostApplicationBuilder AddPersistentState AddPersistentState(hostApplicationBuilder); - public static SitkoCoreApplicationBuilder AddPersistentState( - this SitkoCoreApplicationBuilder applicationBuilder) + public static ISitkoCoreApplicationBuilder AddPersistentState( + this ISitkoCoreApplicationBuilder applicationBuilder) where TCompressor : class, IStateCompressor where TComponentState : class, ICompressedPersistentComponentState => applicationBuilder.ConfigureServices(collection => collection.AddScoped() .AddScoped()); - public static SitkoCoreApplicationBuilder AddPersistentState(this SitkoCoreApplicationBuilder applicationBuilder) => + public static ISitkoCoreApplicationBuilder + AddPersistentState(this ISitkoCoreApplicationBuilder applicationBuilder) => AddPersistentState(applicationBuilder); } diff --git a/src/Sitko.Core.Configuration.Vault/ApplicationExtensions.cs b/src/Sitko.Core.Configuration.Vault/ApplicationExtensions.cs index 3143b0f26..9444e9eb4 100644 --- a/src/Sitko.Core.Configuration.Vault/ApplicationExtensions.cs +++ b/src/Sitko.Core.Configuration.Vault/ApplicationExtensions.cs @@ -22,13 +22,13 @@ public static IHostApplicationBuilder AddVaultConfiguration(this IHostApplicatio return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddVaultConfiguration(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddVaultConfiguration(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddVaultConfiguration(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddVaultConfiguration(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Consul.Web/ApplicationExtensions.cs b/src/Sitko.Core.Consul.Web/ApplicationExtensions.cs index 93b2adacd..124df6931 100644 --- a/src/Sitko.Core.Consul.Web/ApplicationExtensions.cs +++ b/src/Sitko.Core.Consul.Web/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddConsulWeb(this IHostApplicationBuilder return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddConsulWeb(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddConsulWeb(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddConsulWeb(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddConsulWeb(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Consul/ApplicationExtensions.cs b/src/Sitko.Core.Consul/ApplicationExtensions.cs index cf851a6a6..5d436d256 100644 --- a/src/Sitko.Core.Consul/ApplicationExtensions.cs +++ b/src/Sitko.Core.Consul/ApplicationExtensions.cs @@ -21,11 +21,11 @@ public static IHostApplicationBuilder AddConsul(this IHostApplicationBuilder hos return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddConsul(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddConsul(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddConsul(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddConsul(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Db.InMemory/ApplicationExtensions.cs b/src/Sitko.Core.Db.InMemory/ApplicationExtensions.cs index 9ecf757b7..ee3b8abf8 100644 --- a/src/Sitko.Core.Db.InMemory/ApplicationExtensions.cs +++ b/src/Sitko.Core.Db.InMemory/ApplicationExtensions.cs @@ -28,8 +28,8 @@ public static IHostApplicationBuilder AddInMemoryDatabase( return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddInMemoryDatabase( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddInMemoryDatabase( + this ISitkoCoreApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) where TDbContext : DbContext => @@ -37,8 +37,8 @@ public static SitkoCoreApplicationBuilder AddInMemoryDatabase( .AddModule, InMemoryDatabaseModuleOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddInMemoryDatabase( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddInMemoryDatabase( + this ISitkoCoreApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) where TDbContext : DbContext => diff --git a/src/Sitko.Core.Db.Postgres/ApplicationExtensions.cs b/src/Sitko.Core.Db.Postgres/ApplicationExtensions.cs index bc06dd40c..b2e27a7c7 100644 --- a/src/Sitko.Core.Db.Postgres/ApplicationExtensions.cs +++ b/src/Sitko.Core.Db.Postgres/ApplicationExtensions.cs @@ -28,8 +28,8 @@ public static IHostApplicationBuilder AddPostgresDatabase( return applicationBuilder; } - public static SitkoCoreApplicationBuilder AddPostgresDatabase( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddPostgresDatabase( + this ISitkoCoreApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) where TDbContext : DbContext => @@ -37,8 +37,8 @@ public static SitkoCoreApplicationBuilder AddPostgresDatabase( .AddModule, PostgresDatabaseModuleOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddPostgresDatabase( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddPostgresDatabase( + this ISitkoCoreApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) where TDbContext : DbContext => diff --git a/src/Sitko.Core.ElasticStack/ApplicationExtensions.cs b/src/Sitko.Core.ElasticStack/ApplicationExtensions.cs index 2a7aa12ae..9b5d3e9be 100644 --- a/src/Sitko.Core.ElasticStack/ApplicationExtensions.cs +++ b/src/Sitko.Core.ElasticStack/ApplicationExtensions.cs @@ -21,11 +21,11 @@ public static IHostApplicationBuilder AddElasticStack(this IHostApplicationBuild return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddElasticStack(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddElasticStack(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddElasticStack(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddElasticStack(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Email.MailGun/ApplicationExtensions.cs b/src/Sitko.Core.Email.MailGun/ApplicationExtensions.cs index 56632e49c..f18c71abb 100644 --- a/src/Sitko.Core.Email.MailGun/ApplicationExtensions.cs +++ b/src/Sitko.Core.Email.MailGun/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddMailGunEmail(this IHostApplicationBuild return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddMailGunEmail(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddMailGunEmail(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddMailGunEmail(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddMailGunEmail(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Email.Smtp/ApplicationExtensions.cs b/src/Sitko.Core.Email.Smtp/ApplicationExtensions.cs index 20a24eabc..bc1f785cf 100644 --- a/src/Sitko.Core.Email.Smtp/ApplicationExtensions.cs +++ b/src/Sitko.Core.Email.Smtp/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddSmtpEmail(this IHostApplicationBuilder return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddSmtpEmail(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddSmtpEmail(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddSmtpEmail(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddSmtpEmail(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Graylog/ApplicationExtensions.cs b/src/Sitko.Core.Graylog/ApplicationExtensions.cs index fb830a5d8..1dcffc2fb 100644 --- a/src/Sitko.Core.Graylog/ApplicationExtensions.cs +++ b/src/Sitko.Core.Graylog/ApplicationExtensions.cs @@ -21,11 +21,11 @@ public static IHostApplicationBuilder AddGraylog(this IHostApplicationBuilder ho return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddGraylog(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddGraylog(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddGraylog(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddGraylog(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Grpc.Client.Consul/ApplicationExtensions.cs b/src/Sitko.Core.Grpc.Client.Consul/ApplicationExtensions.cs index 74d7aab46..4ae890d4f 100644 --- a/src/Sitko.Core.Grpc.Client.Consul/ApplicationExtensions.cs +++ b/src/Sitko.Core.Grpc.Client.Consul/ApplicationExtensions.cs @@ -26,16 +26,16 @@ public static IHostApplicationBuilder AddConsulGrpcClient(this IHostApp return applicationBuilder; } - public static SitkoCoreApplicationBuilder AddConsulGrpcClient( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddConsulGrpcClient( + this ISitkoCoreApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) where TClient : ClientBase => applicationBuilder.AddModule, ConsulGrpcClientModuleOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddConsulGrpcClient( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddConsulGrpcClient( + this ISitkoCoreApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) where TClient : ClientBase => diff --git a/src/Sitko.Core.Grpc.Client.Web/ApplicationExtensions.cs b/src/Sitko.Core.Grpc.Client.Web/ApplicationExtensions.cs index dd2481dd8..5941d33b7 100644 --- a/src/Sitko.Core.Grpc.Client.Web/ApplicationExtensions.cs +++ b/src/Sitko.Core.Grpc.Client.Web/ApplicationExtensions.cs @@ -28,8 +28,8 @@ public static IHostApplicationBuilder AddGrpcWebClient(this IHostApplic return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddGrpcWebClient( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddGrpcWebClient( + this ISitkoCoreApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) where TClient : ClientBase => @@ -41,8 +41,8 @@ public static SitkoCoreApplicationBuilder AddGrpcWebClient( }, optionsKey); - public static SitkoCoreApplicationBuilder AddGrpcWebClient( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddGrpcWebClient( + this ISitkoCoreApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) where TClient : ClientBase => diff --git a/src/Sitko.Core.Grpc.Client/ApplicationExtensions.cs b/src/Sitko.Core.Grpc.Client/ApplicationExtensions.cs index 4ee076ce8..564834ec6 100644 --- a/src/Sitko.Core.Grpc.Client/ApplicationExtensions.cs +++ b/src/Sitko.Core.Grpc.Client/ApplicationExtensions.cs @@ -29,8 +29,8 @@ public static IHostApplicationBuilder AddExternalGrpcClient( return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddExternalGrpcClient( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddExternalGrpcClient( + this ISitkoCoreApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) where TClient : ClientBase => @@ -38,8 +38,8 @@ public static SitkoCoreApplicationBuilder AddExternalGrpcClient( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddExternalGrpcClient( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddExternalGrpcClient( + this ISitkoCoreApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) where TClient : ClientBase => diff --git a/src/Sitko.Core.Grpc.Server.Consul/ApplicationExtensions.cs b/src/Sitko.Core.Grpc.Server.Consul/ApplicationExtensions.cs index 614d2a0ca..ae6767798 100644 --- a/src/Sitko.Core.Grpc.Server.Consul/ApplicationExtensions.cs +++ b/src/Sitko.Core.Grpc.Server.Consul/ApplicationExtensions.cs @@ -23,13 +23,13 @@ public static IHostApplicationBuilder AddConsulGrpcServer(this IHostApplicationB return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddConsulGrpcServer(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddConsulGrpcServer(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddConsulGrpcServer(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddConsulGrpcServer(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule( diff --git a/src/Sitko.Core.Grpc.Server/ApplicationExtensions.cs b/src/Sitko.Core.Grpc.Server/ApplicationExtensions.cs index d519245c6..09e450764 100644 --- a/src/Sitko.Core.Grpc.Server/ApplicationExtensions.cs +++ b/src/Sitko.Core.Grpc.Server/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddGrpcServer(this IHostApplicationBuilder return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddGrpcServer(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddGrpcServer(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddGrpcServer(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddGrpcServer(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.HangFire/ApplicationExtensions.cs b/src/Sitko.Core.HangFire/ApplicationExtensions.cs index 8ea9b995e..cb235301a 100644 --- a/src/Sitko.Core.HangFire/ApplicationExtensions.cs +++ b/src/Sitko.Core.HangFire/ApplicationExtensions.cs @@ -23,13 +23,13 @@ public static IHostApplicationBuilder AddHangfirePostgres(this IHostApplicationB return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddHangfirePostgres(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddHangfirePostgres(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule, HangfirePostgresModuleOptions>( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddHangfirePostgres(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddHangfirePostgres(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule, HangfirePostgresModuleOptions>( diff --git a/src/Sitko.Core.Health.Teams/ApplicationExtensions.cs b/src/Sitko.Core.Health.Teams/ApplicationExtensions.cs index d51b106e0..a04bcd06e 100644 --- a/src/Sitko.Core.Health.Teams/ApplicationExtensions.cs +++ b/src/Sitko.Core.Health.Teams/ApplicationExtensions.cs @@ -22,15 +22,15 @@ public static IHostApplicationBuilder AddTeamsHealthReporter(this IHostApplicati return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddTeamsHealthReporter( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddTeamsHealthReporter( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddTeamsHealthReporter( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddTeamsHealthReporter( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Health.Telegram/ApplicationExtensions.cs b/src/Sitko.Core.Health.Telegram/ApplicationExtensions.cs index 095aee66d..94147f3d9 100644 --- a/src/Sitko.Core.Health.Telegram/ApplicationExtensions.cs +++ b/src/Sitko.Core.Health.Telegram/ApplicationExtensions.cs @@ -23,15 +23,15 @@ public static IHostApplicationBuilder AddTelegramHealthReporter(this IHostApplic return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddTelegramHealthReporter( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddTelegramHealthReporter( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddTelegramHealthReporter( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddTelegramHealthReporter( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, diff --git a/src/Sitko.Core.IdProvider.SonyFlake/ApplicationExtensions.cs b/src/Sitko.Core.IdProvider.SonyFlake/ApplicationExtensions.cs index 84a44b998..3a66d8fe9 100644 --- a/src/Sitko.Core.IdProvider.SonyFlake/ApplicationExtensions.cs +++ b/src/Sitko.Core.IdProvider.SonyFlake/ApplicationExtensions.cs @@ -23,15 +23,15 @@ public static IHostApplicationBuilder AddSonyFlakeIdProvider(this IHostApplicati return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddSonyFlakeIdProvider( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddSonyFlakeIdProvider( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddSonyFlakeIdProvider( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddSonyFlakeIdProvider( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, diff --git a/src/Sitko.Core.Identity/ApplicationExtensions.cs b/src/Sitko.Core.Identity/ApplicationExtensions.cs index bb3c809b5..7d4a60474 100644 --- a/src/Sitko.Core.Identity/ApplicationExtensions.cs +++ b/src/Sitko.Core.Identity/ApplicationExtensions.cs @@ -33,8 +33,8 @@ public static IHostApplicationBuilder AddIdentity return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddIdentity( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddIdentity( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) where TUser : IdentityUser where TRole : IdentityRole @@ -43,8 +43,8 @@ public static SitkoCoreApplicationBuilder AddIdentity, IdentityModuleOptions>( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddIdentity( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddIdentity( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) where TUser : IdentityUser where TRole : IdentityRole diff --git a/src/Sitko.Core.ImgProxy/ApplicationExtensions.cs b/src/Sitko.Core.ImgProxy/ApplicationExtensions.cs index 139badfd3..941a0f03b 100644 --- a/src/Sitko.Core.ImgProxy/ApplicationExtensions.cs +++ b/src/Sitko.Core.ImgProxy/ApplicationExtensions.cs @@ -23,13 +23,13 @@ public static IHostApplicationBuilder AddImgProxy(this IHostApplicationBuilder h return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddImgProxy(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddImgProxy(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder .AddModule( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddImgProxy(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddImgProxy(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder .AddModule( diff --git a/src/Sitko.Core.MediatR/ApplicationExtensions.cs b/src/Sitko.Core.MediatR/ApplicationExtensions.cs index 00fc6435d..b0a0765f5 100644 --- a/src/Sitko.Core.MediatR/ApplicationExtensions.cs +++ b/src/Sitko.Core.MediatR/ApplicationExtensions.cs @@ -23,13 +23,13 @@ public static IHostApplicationBuilder AddMediatR(this IHostApplicatio return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddMediatR(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddMediatR(this ISitkoCoreApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) => applicationBuilder.AddModule, MediatRModuleOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddMediatR(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddMediatR(this ISitkoCoreApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) => applicationBuilder.AddModule, MediatRModuleOptions>(configure, diff --git a/src/Sitko.Core.NewRelic.Logging/ApplicationExtensions.cs b/src/Sitko.Core.NewRelic.Logging/ApplicationExtensions.cs index 0e5ca7cd5..587d17c58 100644 --- a/src/Sitko.Core.NewRelic.Logging/ApplicationExtensions.cs +++ b/src/Sitko.Core.NewRelic.Logging/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddNewRelicLogging(this IHostApplicationBu return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddNewRelicLogging(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddNewRelicLogging(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddNewRelicLogging(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddNewRelicLogging(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Pdf/ApplicationExtensions.cs b/src/Sitko.Core.Pdf/ApplicationExtensions.cs index da29c9de6..0da2f2ee4 100644 --- a/src/Sitko.Core.Pdf/ApplicationExtensions.cs +++ b/src/Sitko.Core.Pdf/ApplicationExtensions.cs @@ -14,6 +14,6 @@ public static IHostApplicationBuilder AddPdfRenderer(this IHostApplicationBuilde return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddPdfRenderer(this SitkoCoreApplicationBuilder applicationBuilder) => + public static ISitkoCoreApplicationBuilder AddPdfRenderer(this ISitkoCoreApplicationBuilder applicationBuilder) => applicationBuilder.AddModule(); } diff --git a/src/Sitko.Core.Puppeteer/ApplicationExtensions.cs b/src/Sitko.Core.Puppeteer/ApplicationExtensions.cs index bae3b2fe5..4f7532bb1 100644 --- a/src/Sitko.Core.Puppeteer/ApplicationExtensions.cs +++ b/src/Sitko.Core.Puppeteer/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddPuppeteer(this IHostApplicationBuilder return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddPuppeteer(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddPuppeteer(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddPuppeteer(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddPuppeteer(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Queue.Apm/ApplicationExtensions.cs b/src/Sitko.Core.Queue.Apm/ApplicationExtensions.cs index add8339e3..1c39f0de6 100644 --- a/src/Sitko.Core.Queue.Apm/ApplicationExtensions.cs +++ b/src/Sitko.Core.Queue.Apm/ApplicationExtensions.cs @@ -13,6 +13,6 @@ public static IHostApplicationBuilder AddQueueElasticApm(this IHostApplicationBu return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddQueueElasticApm(this SitkoCoreApplicationBuilder applicationBuilder) => + public static ISitkoCoreApplicationBuilder AddQueueElasticApm(this ISitkoCoreApplicationBuilder applicationBuilder) => applicationBuilder.AddModule(); } diff --git a/src/Sitko.Core.Queue.InMemory/ApplicationExtensions.cs b/src/Sitko.Core.Queue.InMemory/ApplicationExtensions.cs index ea900d3e9..d725ff723 100644 --- a/src/Sitko.Core.Queue.InMemory/ApplicationExtensions.cs +++ b/src/Sitko.Core.Queue.InMemory/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddInMemoryQueue(this IHostApplicationBuil return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddInMemoryQueue(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddInMemoryQueue(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddInMemoryQueue(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddInMemoryQueue(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Queue.Nats/ApplicationExtensions.cs b/src/Sitko.Core.Queue.Nats/ApplicationExtensions.cs index 34a7ab4a8..12c97dee1 100644 --- a/src/Sitko.Core.Queue.Nats/ApplicationExtensions.cs +++ b/src/Sitko.Core.Queue.Nats/ApplicationExtensions.cs @@ -21,11 +21,11 @@ public static IHostApplicationBuilder AddNatsQueue(this IHostApplicationBuilder return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddNatsQueue(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddNatsQueue(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddNatsQueue(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddNatsQueue(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Repository.EntityFrameworkCore/ApplicationExtensions.cs b/src/Sitko.Core.Repository.EntityFrameworkCore/ApplicationExtensions.cs index 4484f6c3d..0ff3110de 100644 --- a/src/Sitko.Core.Repository.EntityFrameworkCore/ApplicationExtensions.cs +++ b/src/Sitko.Core.Repository.EntityFrameworkCore/ApplicationExtensions.cs @@ -41,18 +41,18 @@ public static IHostApplicationBuilder AddEFRepositories( return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddEFRepositories(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddEFRepositories(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddEFRepositories(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddEFRepositories(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddEFRepositories( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddEFRepositories( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule( @@ -63,8 +63,8 @@ public static SitkoCoreApplicationBuilder AddEFRepositories( }, optionsKey); - public static SitkoCoreApplicationBuilder AddEFRepositories( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddEFRepositories( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(moduleOptions => diff --git a/src/Sitko.Core.Repository.Remote.Wasm/ApplicationExtensions.cs b/src/Sitko.Core.Repository.Remote.Wasm/ApplicationExtensions.cs index 40aa3a07e..f3871141b 100644 --- a/src/Sitko.Core.Repository.Remote.Wasm/ApplicationExtensions.cs +++ b/src/Sitko.Core.Repository.Remote.Wasm/ApplicationExtensions.cs @@ -25,15 +25,15 @@ public static IHostApplicationBuilder AddWasmHttpRepositoryTransport( return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddWasmHttpRepositoryTransport( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddWasmHttpRepositoryTransport( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddWasmHttpRepositoryTransport( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddWasmHttpRepositoryTransport( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, diff --git a/src/Sitko.Core.Repository.Remote/ApplicationExtensions.cs b/src/Sitko.Core.Repository.Remote/ApplicationExtensions.cs index d7ce5a1f8..c9ce45bba 100644 --- a/src/Sitko.Core.Repository.Remote/ApplicationExtensions.cs +++ b/src/Sitko.Core.Repository.Remote/ApplicationExtensions.cs @@ -59,18 +59,18 @@ public static IHostApplicationBuilder AddHttpRepositoryTransport( return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddRemoteRepositories(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddRemoteRepositories(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddRemoteRepositories(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddRemoteRepositories(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddRemoteRepositories( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddRemoteRepositories( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule( @@ -81,8 +81,8 @@ public static SitkoCoreApplicationBuilder AddRemoteRepositories( }, optionsKey); - public static SitkoCoreApplicationBuilder AddRemoteRepositories( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddRemoteRepositories( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(moduleOptions => @@ -92,15 +92,15 @@ public static SitkoCoreApplicationBuilder AddRemoteRepositories( }, optionsKey); - public static SitkoCoreApplicationBuilder AddHttpRepositoryTransport( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddHttpRepositoryTransport( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddHttpRepositoryTransport( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddHttpRepositoryTransport( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, diff --git a/src/Sitko.Core.Repository.Search/ApplicationExtensions.cs b/src/Sitko.Core.Repository.Search/ApplicationExtensions.cs index 7e7cd43d0..0d9c7e751 100644 --- a/src/Sitko.Core.Repository.Search/ApplicationExtensions.cs +++ b/src/Sitko.Core.Repository.Search/ApplicationExtensions.cs @@ -13,7 +13,7 @@ public static IHostApplicationBuilder AddSearchRepository(this IHostApplicationB return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder - AddSearchRepository(this SitkoCoreApplicationBuilder applicationBuilder) => + public static ISitkoCoreApplicationBuilder + AddSearchRepository(this ISitkoCoreApplicationBuilder applicationBuilder) => applicationBuilder.AddModule(); } diff --git a/src/Sitko.Core.Search.ElasticSearch/ApplicationExtensions.cs b/src/Sitko.Core.Search.ElasticSearch/ApplicationExtensions.cs index 0c6e45fc0..56004eafb 100644 --- a/src/Sitko.Core.Search.ElasticSearch/ApplicationExtensions.cs +++ b/src/Sitko.Core.Search.ElasticSearch/ApplicationExtensions.cs @@ -23,12 +23,12 @@ public static IHostApplicationBuilder AddElasticSearch(this IHostApplicationBuil return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddElasticSearch(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddElasticSearch(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddElasticSearch(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddElasticSearch(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); diff --git a/src/Sitko.Core.Sentry/ApplicationExtensions.cs b/src/Sitko.Core.Sentry/ApplicationExtensions.cs index f5cd09975..330828878 100644 --- a/src/Sitko.Core.Sentry/ApplicationExtensions.cs +++ b/src/Sitko.Core.Sentry/ApplicationExtensions.cs @@ -21,11 +21,11 @@ public static IHostApplicationBuilder AddSentry(this IHostApplicationBuilder hos return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddSentry(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddSentry(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddSentry(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddSentry(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Storage.FileSystem/ApplicationExtensions.cs b/src/Sitko.Core.Storage.FileSystem/ApplicationExtensions.cs index 878eb8395..c2c06229c 100644 --- a/src/Sitko.Core.Storage.FileSystem/ApplicationExtensions.cs +++ b/src/Sitko.Core.Storage.FileSystem/ApplicationExtensions.cs @@ -12,7 +12,7 @@ public static IHostApplicationBuilder AddFileSystemStorage( Action configure, string? optionsKey = null) where TStorageOptions : StorageOptions, IFileSystemStorageOptions, new() { - hostApplicationBuilder.AddSitkoCore().AddFileSystemStorage(configure, optionsKey); + hostApplicationBuilder.AddSitkoCore().AddFileSystemStorage(configure, optionsKey); return hostApplicationBuilder; } @@ -21,7 +21,7 @@ public static IHostApplicationBuilder AddFileSystemStorage( Action? configure = null, string? optionsKey = null) where TStorageOptions : StorageOptions, IFileSystemStorageOptions, new() { - hostApplicationBuilder.AddSitkoCore().AddFileSystemStorage(configure, optionsKey); + hostApplicationBuilder.AddSitkoCore().AddFileSystemStorage(configure, optionsKey); return hostApplicationBuilder; } @@ -31,7 +31,7 @@ public static IHostApplicationBuilder AddFileSystemStorageMetadata().AddFileSystemStorageMetadata(configure, optionsKey); return hostApplicationBuilder; } @@ -41,40 +41,40 @@ public static IHostApplicationBuilder AddFileSystemStorageMetadata().AddFileSystemStorageMetadata(configure, optionsKey); return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddFileSystemStorage( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddFileSystemStorage( + this ISitkoCoreServerApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) where TStorageOptions : StorageOptions, IFileSystemStorageOptions, new() => applicationBuilder.AddModule, TStorageOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddFileSystemStorage( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddFileSystemStorage( + this ISitkoCoreServerApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) where TStorageOptions : StorageOptions, IFileSystemStorageOptions, new() => applicationBuilder.AddModule, TStorageOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddFileSystemStorageMetadata( - this SitkoCoreApplicationBuilder application, + public static ISitkoCoreApplicationBuilder AddFileSystemStorageMetadata( + this ISitkoCoreServerApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) where TStorageOptions : StorageOptions, IFileSystemStorageOptions, new() => - application + applicationBuilder .AddModule, FileSystemStorageMetadataModuleOptions>( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddFileSystemStorageMetadata( - this SitkoCoreApplicationBuilder application, + public static ISitkoCoreApplicationBuilder AddFileSystemStorageMetadata( + this ISitkoCoreServerApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) where TStorageOptions : StorageOptions, IFileSystemStorageOptions, new() => - application + applicationBuilder .AddModule, FileSystemStorageMetadataModuleOptions>( configure, optionsKey); diff --git a/src/Sitko.Core.Storage.ImgProxy/ApplicationExtensions.cs b/src/Sitko.Core.Storage.ImgProxy/ApplicationExtensions.cs index 35a448fa0..24ec20e8f 100644 --- a/src/Sitko.Core.Storage.ImgProxy/ApplicationExtensions.cs +++ b/src/Sitko.Core.Storage.ImgProxy/ApplicationExtensions.cs @@ -27,8 +27,8 @@ public static IHostApplicationBuilder AddImgProxyStorage( return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddImgProxyStorage( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddImgProxyStorage( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) where TStorageOptions : StorageOptions => @@ -36,8 +36,8 @@ public static SitkoCoreApplicationBuilder AddImgProxyStorage( .AddModule, BaseApplicationModuleOptions>( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddImgProxyStorage( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddImgProxyStorage( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) where TStorageOptions : StorageOptions => diff --git a/src/Sitko.Core.Storage.Metadata.Postgres/ApplicationExtensions.cs b/src/Sitko.Core.Storage.Metadata.Postgres/ApplicationExtensions.cs index 073ed0e4d..77d5a65c3 100644 --- a/src/Sitko.Core.Storage.Metadata.Postgres/ApplicationExtensions.cs +++ b/src/Sitko.Core.Storage.Metadata.Postgres/ApplicationExtensions.cs @@ -26,8 +26,8 @@ public static IHostApplicationBuilder AddPostgresStorageMetadata( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddPostgresStorageMetadata( + this ISitkoCoreApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) where TStorageOptions : StorageOptions => @@ -36,8 +36,8 @@ public static SitkoCoreApplicationBuilder AddPostgresStorageMetadata>( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddPostgresStorageMetadata( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddPostgresStorageMetadata( + this ISitkoCoreApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) where TStorageOptions : StorageOptions => applicationBuilder diff --git a/src/Sitko.Core.Storage.Remote/ApplicationExtensions.cs b/src/Sitko.Core.Storage.Remote/ApplicationExtensions.cs index cc0d02c6f..f1bfc9cff 100644 --- a/src/Sitko.Core.Storage.Remote/ApplicationExtensions.cs +++ b/src/Sitko.Core.Storage.Remote/ApplicationExtensions.cs @@ -25,15 +25,15 @@ public static IHostApplicationBuilder AddRemoteStorage( return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddRemoteStorage( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddRemoteStorage( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) where TStorageOptions : StorageOptions, IRemoteStorageOptions, new() => applicationBuilder.AddModule, TStorageOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddRemoteStorage( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddRemoteStorage( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) where TStorageOptions : StorageOptions, IRemoteStorageOptions, new() => applicationBuilder.AddModule, TStorageOptions>(configure, diff --git a/src/Sitko.Core.Storage.S3/ApplicationExtensions.cs b/src/Sitko.Core.Storage.S3/ApplicationExtensions.cs index 84bb9296e..86ac98245 100644 --- a/src/Sitko.Core.Storage.S3/ApplicationExtensions.cs +++ b/src/Sitko.Core.Storage.S3/ApplicationExtensions.cs @@ -45,20 +45,20 @@ public static IHostApplicationBuilder AddS3StorageMetadata( return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddS3Storage( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddS3Storage( + this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) where TStorageOptions : S3StorageOptions, new() => applicationBuilder.AddModule, TStorageOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddS3Storage( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddS3Storage( + this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) where TStorageOptions : S3StorageOptions, new() => applicationBuilder.AddModule, TStorageOptions>(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddS3StorageMetadata( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddS3StorageMetadata( + this ISitkoCoreApplicationBuilder applicationBuilder, Action> configure, string? optionsKey = null) where TStorageOptions : S3StorageOptions, new() => @@ -66,8 +66,8 @@ public static SitkoCoreApplicationBuilder AddS3StorageMetadata( .AddModule, S3StorageMetadataModuleOptions>( configure, optionsKey); - public static SitkoCoreApplicationBuilder AddS3StorageMetadata( - this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddS3StorageMetadata( + this ISitkoCoreApplicationBuilder applicationBuilder, Action>? configure = null, string? optionsKey = null) where TStorageOptions : S3StorageOptions, new() => diff --git a/src/Sitko.Core.Swagger/ApplicationExtensions.cs b/src/Sitko.Core.Swagger/ApplicationExtensions.cs index 2f49d4ed8..04013542d 100644 --- a/src/Sitko.Core.Swagger/ApplicationExtensions.cs +++ b/src/Sitko.Core.Swagger/ApplicationExtensions.cs @@ -21,11 +21,11 @@ public static IHostApplicationBuilder AddSwagger(this IHostApplicationBuilder ho return hostApplicationBuilder; } - public static SitkoCoreApplicationBuilder AddSwagger(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddSwagger(this ISitkoCoreApplicationBuilder applicationBuilder, Action configure, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); - public static SitkoCoreApplicationBuilder AddSwagger(this SitkoCoreApplicationBuilder applicationBuilder, + public static ISitkoCoreApplicationBuilder AddSwagger(this ISitkoCoreApplicationBuilder applicationBuilder, Action? configure = null, string? optionsKey = null) => applicationBuilder.AddModule(configure, optionsKey); } diff --git a/src/Sitko.Core.Xunit.Web/WebTestScope.cs b/src/Sitko.Core.Xunit.Web/WebTestScope.cs index 169bdd2bd..5eaeb259c 100644 --- a/src/Sitko.Core.Xunit.Web/WebTestScope.cs +++ b/src/Sitko.Core.Xunit.Web/WebTestScope.cs @@ -2,14 +2,19 @@ using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Sitko.Core.App; using Sitko.Core.App.Web; namespace Sitko.Core.Xunit.Web; public class WebTestScope : WebTestScope { - protected override HostApplicationBuilder CreateHostBuilder() => - Microsoft.Extensions.Hosting.Host.CreateApplicationBuilder(); + protected override HostApplicationBuilder CreateHostBuilder() + { + var builder = Microsoft.Extensions.Hosting.Host.CreateApplicationBuilder(); + builder.AddSitkoCore(); + return builder; + } protected override IHost BuildApplication(HostApplicationBuilder builder) => builder.Build(); } @@ -27,7 +32,7 @@ protected virtual WebApplicationBuilder ConfigureWebApplication(WebApplicationBu public override async Task BeforeConfiguredAsync(string name) { var builder = WebApplication.CreateBuilder(); - + builder.AddSitkoCore(); ConfigureWebApplication(builder, name); builder.Services.AddMvc(options => options.EnableEndpointRouting = false).AddApplicationPart(GetType().Assembly) .AddControllersAsServices(); diff --git a/src/Sitko.Core.Xunit/BaseTestScope.cs b/src/Sitko.Core.Xunit/BaseTestScope.cs index 3d09df58b..26be44900 100644 --- a/src/Sitko.Core.Xunit/BaseTestScope.cs +++ b/src/Sitko.Core.Xunit/BaseTestScope.cs @@ -48,7 +48,7 @@ public Task ConfigureAsync(string name, ITestOutputHelper testOutputHelper) hostApplicationBuilder.Services.Configure(hostApplicationBuilder.Configuration.GetSection("Tests")); ConfigureServices(hostApplicationBuilder, name); - hostApplicationBuilder.AddSitkoCore(Array.Empty()) + hostApplicationBuilder.AddSitkoCore() .ConfigureLogging((_, loggerConfiguration) => { loggerConfiguration = loggerConfiguration.WriteTo.TestOutput(testOutputHelper, @@ -136,7 +136,13 @@ protected virtual IHostApplicationBuilder ConfigureServices(IHostApplicationBuil public abstract class BaseTestScope : BaseTestScope where TConfig : BaseTestConfig, new() { - protected override HostApplicationBuilder CreateHostBuilder() => Host.CreateApplicationBuilder(); + protected override HostApplicationBuilder CreateHostBuilder() + { + var builder = Host.CreateApplicationBuilder(); + builder.AddSitkoCore(); + return builder; + } + protected override IHost BuildApplication(HostApplicationBuilder builder) => builder.Build(); } diff --git a/src/Sitko.Core.Xunit/DbBaseTestScope.cs b/src/Sitko.Core.Xunit/DbBaseTestScope.cs index 307da14f2..10d1a9f37 100644 --- a/src/Sitko.Core.Xunit/DbBaseTestScope.cs +++ b/src/Sitko.Core.Xunit/DbBaseTestScope.cs @@ -134,5 +134,10 @@ public abstract class where TDbContext : DbContext { protected override IHost BuildApplication(HostApplicationBuilder builder) => builder.Build(); - protected override HostApplicationBuilder CreateHostBuilder() => Host.CreateApplicationBuilder(); + protected override HostApplicationBuilder CreateHostBuilder() + { + var builder = Host.CreateApplicationBuilder(); + builder.AddSitkoCore(); + return builder; + } } diff --git a/tests/Sitko.Core.App.Tests/ILocalizationTests.cs b/tests/Sitko.Core.App.Tests/ILocalizationTests.cs index 19743b4eb..137a4d281 100644 --- a/tests/Sitko.Core.App.Tests/ILocalizationTests.cs +++ b/tests/Sitko.Core.App.Tests/ILocalizationTests.cs @@ -165,9 +165,13 @@ public class Default public class LocalizationTestScope : BaseTestScope { - protected override IHostApplicationBuilder ConfigureApplication(IHostApplicationBuilder hostBuilder, string name) => + protected override IHostApplicationBuilder ConfigureApplication(IHostApplicationBuilder hostBuilder, string name) + { base.ConfigureApplication(hostBuilder, name) + .AddSitkoCore() .AddJsonLocalization(options => options.AddDefaultResource()); + return hostBuilder; + } } public class NoLocalizationTestScope : BaseTestScope diff --git a/tests/Sitko.Core.Grpc.Server.Tests/GrpcServerTest.cs b/tests/Sitko.Core.Grpc.Server.Tests/GrpcServerTest.cs index f7ed43f9c..4bd2d3618 100644 --- a/tests/Sitko.Core.Grpc.Server.Tests/GrpcServerTest.cs +++ b/tests/Sitko.Core.Grpc.Server.Tests/GrpcServerTest.cs @@ -18,7 +18,7 @@ public GrpcServerTest(ITestOutputHelper testOutputHelper) : base(testOutputHelpe public async Task TestResponse() { var hostBuilder = WebApplication.CreateBuilder(); - hostBuilder.AddGrpcServer(options => options.RegisterService()); + hostBuilder.AddSitkoCore().AddGrpcServer(options => options.RegisterService()); hostBuilder.WebHost.UseTestServer(); await using var host = hostBuilder.Build(); host.MapSitkoCore(); diff --git a/tests/Sitko.Core.Repository.EntityFrameworkCore.Tests/Data/TPH/TPHDbContextsTestScope.cs b/tests/Sitko.Core.Repository.EntityFrameworkCore.Tests/Data/TPH/TPHDbContextsTestScope.cs index 86cffe9ba..2a265c8f4 100644 --- a/tests/Sitko.Core.Repository.EntityFrameworkCore.Tests/Data/TPH/TPHDbContextsTestScope.cs +++ b/tests/Sitko.Core.Repository.EntityFrameworkCore.Tests/Data/TPH/TPHDbContextsTestScope.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Hosting; +using Sitko.Core.App; using Sitko.Core.Xunit; namespace Sitko.Core.Repository.EntityFrameworkCore.Tests.Data.TPH; @@ -15,7 +16,12 @@ await dbContext.AddAsync( await dbContext.SaveChangesAsync(); } - protected override HostApplicationBuilder CreateHostBuilder() => Host.CreateApplicationBuilder(); + protected override HostApplicationBuilder CreateHostBuilder() + { + var builder = Host.CreateApplicationBuilder(); + builder.AddSitkoCore(); + return builder; + } protected override IHost BuildApplication(HostApplicationBuilder builder) => builder.Build(); }