load different services depending on host-env
This commit is contained in:
@@ -2,17 +2,11 @@
|
|||||||
|
|
||||||
namespace Finch.Configuration;
|
namespace Finch.Configuration;
|
||||||
|
|
||||||
public class FinchStartupOptions : IFinchStartupOptions
|
public class FinchStartupOptions(IMvcBuilder mvc) : IFinchStartupOptions
|
||||||
{
|
{
|
||||||
public IList<IAssemblyDiscoveryRule> AssemblyDiscoveryRules { get; } = new List<IAssemblyDiscoveryRule>();
|
public IList<IAssemblyDiscoveryRule> AssemblyDiscoveryRules { get; } = new List<IAssemblyDiscoveryRule>();
|
||||||
|
|
||||||
public IMvcBuilder Mvc { get; }
|
public IMvcBuilder Mvc { get; } = mvc;
|
||||||
|
|
||||||
|
|
||||||
public FinchStartupOptions(IMvcBuilder mvc)
|
|
||||||
{
|
|
||||||
Mvc = mvc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IFinchStartupOptions
|
public interface IFinchStartupOptions
|
||||||
|
|||||||
@@ -2,19 +2,12 @@
|
|||||||
|
|
||||||
namespace Finch.Context
|
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)
|
public async Task Invoke(HttpContext httpContext, IFinchContext finchContext)
|
||||||
{
|
{
|
||||||
await finchContext.Resolve(httpContext);
|
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 IServiceCollection Services { get; }
|
||||||
|
|
||||||
public virtual IMvcBuilder Mvc { get; }
|
|
||||||
|
|
||||||
internal static FinchModuleCollection Modules { get; } = new();
|
internal static FinchModuleCollection Modules { get; } = new();
|
||||||
|
|
||||||
readonly IConfiguration _configuration;
|
readonly IConfiguration _configuration;
|
||||||
readonly IFinchStartupOptions _startupOptions;
|
|
||||||
|
|
||||||
|
|
||||||
public FinchBuilder(IServiceCollection services, IConfiguration configuration, Action<IFinchStartupOptions> setupAction)
|
public FinchBuilder(IServiceCollection services, IConfiguration configuration, Action<IFinchStartupOptions> setupAction)
|
||||||
{
|
{
|
||||||
Services = services;
|
Services = services;
|
||||||
Mvc = services.AddMvc();
|
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
|
||||||
// create startup options
|
bool isWeb = services.Any(s => s.ServiceType.FullName == "Microsoft.AspNetCore.Hosting.IWebHostEnvironment");;
|
||||||
_startupOptions = new FinchStartupOptions(Mvc);
|
|
||||||
_startupOptions.AssemblyDiscoveryRules.Add(new FinchAssemblyDiscoveryRule());
|
if (isWeb)
|
||||||
setupAction?.Invoke(_startupOptions);
|
{
|
||||||
|
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");
|
//string appName = configuration.GetValue<string>("Finch:AppName").Or("finch-app");
|
||||||
//services.AddDataProtection();.PersistKeysToRegistry()
|
//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<FinchLoggingModule>();
|
||||||
Modules.Add<FinchCommunicationModule>();
|
Modules.Add<FinchCommunicationModule>();
|
||||||
Modules.Add<FinchMvcModule>();
|
|
||||||
Modules.Add<FinchConfigurationModule>();
|
Modules.Add<FinchConfigurationModule>();
|
||||||
Modules.Add<FinchValidationModule>();
|
Modules.Add<FinchValidationModule>();
|
||||||
Modules.Add<FinchContextModule>();
|
Modules.Add<FinchContextModule>();
|
||||||
Modules.Add<FinchFileStorageModule>();
|
Modules.Add<FinchFileStorageModule>();
|
||||||
//Modules.Add<FinchIdentityModule>();
|
|
||||||
Modules.Add<FinchLocalizationModule>();
|
Modules.Add<FinchLocalizationModule>();
|
||||||
Modules.Add<FinchMailModule>();
|
Modules.Add<FinchMailModule>();
|
||||||
//Modules.Add<FinchMapperModule>();
|
|
||||||
Modules.Add<FinchMediaModule>();
|
Modules.Add<FinchMediaModule>();
|
||||||
//Modules.Add<FinchPageModule>();
|
|
||||||
Modules.Add<FinchRenderingModule>();
|
Modules.Add<FinchRenderingModule>();
|
||||||
Modules.Add<FinchNumberModule>();
|
Modules.Add<FinchNumberModule>();
|
||||||
Modules.Add<FinchRoutingModule>();
|
Modules.Add<FinchRoutingModule>();
|
||||||
|
|||||||
Reference in New Issue
Block a user