load different services depending on host-env
This commit is contained in:
@@ -2,17 +2,11 @@
|
||||
|
||||
namespace Finch.Configuration;
|
||||
|
||||
public class FinchStartupOptions : IFinchStartupOptions
|
||||
public class FinchStartupOptions(IMvcBuilder mvc) : IFinchStartupOptions
|
||||
{
|
||||
public IList<IAssemblyDiscoveryRule> AssemblyDiscoveryRules { get; } = new List<IAssemblyDiscoveryRule>();
|
||||
|
||||
public IMvcBuilder Mvc { get; }
|
||||
|
||||
|
||||
public FinchStartupOptions(IMvcBuilder mvc)
|
||||
{
|
||||
Mvc = mvc;
|
||||
}
|
||||
public IMvcBuilder Mvc { get; } = mvc;
|
||||
}
|
||||
|
||||
public interface IFinchStartupOptions
|
||||
|
||||
@@ -2,19 +2,12 @@
|
||||
|
||||
namespace Finch.Context
|
||||
{
|
||||
public class FinchContextMiddleware
|
||||
public class FinchContextMiddleware(RequestDelegate next)
|
||||
{
|
||||
RequestDelegate _next;
|
||||
|
||||
public FinchContextMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext httpContext, IFinchContext finchContext)
|
||||
{
|
||||
await finchContext.Resolve(httpContext);
|
||||
await _next(httpContext);
|
||||
await next(httpContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-24
@@ -18,53 +18,52 @@ public class FinchBuilder
|
||||
{
|
||||
public virtual IServiceCollection Services { get; }
|
||||
|
||||
public virtual IMvcBuilder Mvc { get; }
|
||||
|
||||
internal static FinchModuleCollection Modules { get; } = new();
|
||||
|
||||
readonly IConfiguration _configuration;
|
||||
readonly IFinchStartupOptions _startupOptions;
|
||||
|
||||
|
||||
public FinchBuilder(IServiceCollection services, IConfiguration configuration, Action<IFinchStartupOptions> setupAction)
|
||||
{
|
||||
Services = services;
|
||||
Mvc = services.AddMvc();
|
||||
_configuration = configuration;
|
||||
|
||||
// create startup options
|
||||
_startupOptions = new FinchStartupOptions(Mvc);
|
||||
_startupOptions.AssemblyDiscoveryRules.Add(new FinchAssemblyDiscoveryRule());
|
||||
setupAction?.Invoke(_startupOptions);
|
||||
bool isWeb = services.Any(s => s.ServiceType.FullName == "Microsoft.AspNetCore.Hosting.IWebHostEnvironment");;
|
||||
|
||||
if (isWeb)
|
||||
{
|
||||
IMvcBuilder mvcBuilder = services.AddMvc();
|
||||
// create startup options
|
||||
IFinchStartupOptions startupOptions = new FinchStartupOptions(mvcBuilder);
|
||||
startupOptions.AssemblyDiscoveryRules.Add(new FinchAssemblyDiscoveryRule());
|
||||
setupAction?.Invoke(startupOptions);
|
||||
|
||||
services.AddControllers();
|
||||
services.AddOutputCache();
|
||||
mvcBuilder = services.AddRazorPages();
|
||||
|
||||
mvcBuilder.AddDataAnnotationsLocalization();
|
||||
|
||||
services.Configure<AntiforgeryOptions>(opts => opts.Cookie.Name = "finch.antiforgery");
|
||||
|
||||
// adds and discovers additional and built-in assemblies
|
||||
new AssemblyDiscovery(mvcBuilder).Execute(startupOptions.AssemblyDiscoveryRules);
|
||||
|
||||
Modules.Add<FinchMvcModule>();
|
||||
}
|
||||
|
||||
//string appName = configuration.GetValue<string>("Finch:AppName").Or("finch-app");
|
||||
//services.AddDataProtection();.PersistKeysToRegistry()
|
||||
|
||||
services.AddControllers();
|
||||
services.AddOutputCache();
|
||||
Mvc = services.AddRazorPages();
|
||||
|
||||
Mvc.AddDataAnnotationsLocalization();
|
||||
|
||||
services.Configure<AntiforgeryOptions>(opts => opts.Cookie.Name = "finch.antiforgery");
|
||||
|
||||
|
||||
// adds and discovers additional and built-in assemblies
|
||||
new AssemblyDiscovery(Mvc).Execute(_startupOptions.AssemblyDiscoveryRules);
|
||||
|
||||
Modules.Add<FinchLoggingModule>();
|
||||
Modules.Add<FinchCommunicationModule>();
|
||||
Modules.Add<FinchMvcModule>();
|
||||
Modules.Add<FinchConfigurationModule>();
|
||||
Modules.Add<FinchValidationModule>();
|
||||
Modules.Add<FinchContextModule>();
|
||||
Modules.Add<FinchFileStorageModule>();
|
||||
//Modules.Add<FinchIdentityModule>();
|
||||
Modules.Add<FinchLocalizationModule>();
|
||||
Modules.Add<FinchMailModule>();
|
||||
//Modules.Add<FinchMapperModule>();
|
||||
Modules.Add<FinchMediaModule>();
|
||||
//Modules.Add<FinchPageModule>();
|
||||
Modules.Add<FinchRenderingModule>();
|
||||
Modules.Add<FinchNumberModule>();
|
||||
Modules.Add<FinchRoutingModule>();
|
||||
|
||||
Reference in New Issue
Block a user