Browse Source

Bugfix and cleanup

pull/170/head
Sebastian Stehle 9 years ago
parent
commit
5d830a5eb6
  1. 3
      src/Squidex/AppConfiguration.cs
  2. 10
      src/Squidex/Config/Domain/EventStoreExtensions.cs
  3. 2
      src/Squidex/Config/Domain/InfrastructureServices.cs
  4. 36
      src/Squidex/Config/Domain/LoggingExtensions.cs
  5. 3
      src/Squidex/Config/Domain/ReadServices.cs
  6. 8
      src/Squidex/Config/Domain/SystemExtensions.cs
  7. 9
      src/Squidex/Config/ServiceExtensions.cs
  8. 5
      src/Squidex/Program.cs
  9. 57
      src/Squidex/WebStartup.cs

3
src/Squidex/AppConfiguration.cs

@ -15,9 +15,12 @@ namespace Squidex
public static void AddAppConfiguration(this IConfigurationBuilder builder, string environmentName, string[] args) public static void AddAppConfiguration(this IConfigurationBuilder builder, string environmentName, string[] args)
{ {
builder.Sources.Clear(); builder.Sources.Clear();
builder.AddJsonFile("appsettings.json", true, true); builder.AddJsonFile("appsettings.json", true, true);
builder.AddJsonFile($"appsettings.{environmentName}.json", true); builder.AddJsonFile($"appsettings.{environmentName}.json", true);
builder.AddEnvironmentVariables(); builder.AddEnvironmentVariables();
builder.AddCommandLine(args); builder.AddCommandLine(args);
} }
} }

10
src/Squidex/Config/Domain/EventStoreExtensions.cs

@ -1,12 +1,12 @@
// ========================================================================== // ==========================================================================
// EventStoreUsages.cs // EventStoreExtensions.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using Microsoft.AspNetCore.Builder; using System;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure.Actors; using Squidex.Infrastructure.Actors;
using Squidex.Infrastructure.CQRS.Events; using Squidex.Infrastructure.CQRS.Events;
@ -16,10 +16,8 @@ namespace Squidex.Config.Domain
{ {
public static class EventStoreExtensions public static class EventStoreExtensions
{ {
public static IApplicationBuilder UseMyEventStore(this IApplicationBuilder app) public static void UseMyEventStore(this IServiceProvider services)
{ {
var services = app.ApplicationServices;
services.GetService<EventConsumerCleaner>().CleanAsync().Wait(); services.GetService<EventConsumerCleaner>().CleanAsync().Wait();
var consumers = services.GetServices<IEventConsumer>(); var consumers = services.GetServices<IEventConsumer>();
@ -35,8 +33,6 @@ namespace Squidex.Config.Domain
services.GetService<RemoteActors>().Connect(consumer.Name, actor); services.GetService<RemoteActors>().Connect(consumer.Name, actor);
} }
} }
return app;
} }
} }
} }

2
src/Squidex/Config/Domain/InfrastructureServices.cs

@ -50,7 +50,7 @@ namespace Squidex.Config.Domain
.As<IExternalSystem>(); .As<IExternalSystem>();
} }
services.AddSingleton(c => new ApplicationInfoLogAppender(typeof(Startup).Assembly, Guid.NewGuid())) services.AddSingleton(c => new ApplicationInfoLogAppender(typeof(Program).Assembly, Guid.NewGuid()))
.As<ILogAppender>(); .As<ILogAppender>();
services.AddSingleton<ActionContextLogAppender>() services.AddSingleton<ActionContextLogAppender>()

36
src/Squidex/Config/Domain/LoggingExtensions.cs

@ -0,0 +1,36 @@
// ==========================================================================
// LoggingExtensions.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Linq;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure.Log;
namespace Squidex.Config.Domain
{
public static class LoggingExtensions
{
public static void LogConfiguration(this IServiceProvider services)
{
var log = services.GetRequiredService<ISemanticLog>();
var config = services.GetRequiredService<IConfiguration>();
log.LogInformation(w => w
.WriteProperty("message", "Application started")
.WriteObject("environment", c =>
{
foreach (var kvp in config.AsEnumerable().Where(kvp => kvp.Value != null))
{
c.WriteProperty(kvp.Key, kvp.Value);
}
}));
}
}
}

3
src/Squidex/Config/Domain/ReadServices.cs

@ -46,8 +46,7 @@ namespace Squidex.Config.Domain
exposeSourceUrl)) exposeSourceUrl))
.As<IGraphQLUrlGenerator>(); .As<IGraphQLUrlGenerator>();
services.AddSingleton(c => c.GetService<IOptions<MyUsageOptions>>()?.Value?.Plans.OrEmpty()) services.AddSingleton(c => c.GetService<IOptions<MyUsageOptions>>()?.Value?.Plans.OrEmpty());
.As<IEnumerable<ConfigAppLimitsPlan>>();
services.AddSingleton<CachingGraphQLService>() services.AddSingleton<CachingGraphQLService>()
.As<IGraphQLService>(); .As<IGraphQLService>();

8
src/Squidex/Config/Domain/SystemExtensions.cs

@ -6,8 +6,8 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure; using Squidex.Infrastructure;
@ -15,16 +15,14 @@ namespace Squidex.Config.Domain
{ {
public static class SystemExtensions public static class SystemExtensions
{ {
public static IApplicationBuilder TestExternalSystems(this IApplicationBuilder app) public static void TestExternalSystems(this IServiceProvider services)
{ {
var systems = app.ApplicationServices.GetRequiredService<IEnumerable<IExternalSystem>>(); var systems = services.GetRequiredService<IEnumerable<IExternalSystem>>();
foreach (var system in systems) foreach (var system in systems)
{ {
system.Connect(); system.Connect();
} }
return app;
} }
} }
} }

9
src/Squidex/Config/ServiceExtensions.cs

@ -27,10 +27,13 @@ namespace Squidex.Config
public InterfaceRegistrator<T> As<TInterface>() public InterfaceRegistrator<T> As<TInterface>()
{ {
this.services.AddSingleton(typeof(TInterface), c => if (typeof(TInterface) != typeof(T))
{ {
return c.GetRequiredService<T>(); this.services.AddSingleton(typeof(TInterface), c =>
}); {
return c.GetRequiredService<T>();
});
}
return this; return this;
} }

5
src/Squidex/Program.cs

@ -20,6 +20,7 @@ namespace Squidex
.UseKestrel(k => { k.AddServerHeader = false; }) .UseKestrel(k => { k.AddServerHeader = false; })
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() .UseIISIntegration()
.UseStartup<WebStartup>()
.ConfigureLogging(builder => .ConfigureLogging(builder =>
{ {
builder.AddSemanticLog(); builder.AddSemanticLog();
@ -28,10 +29,6 @@ namespace Squidex
{ {
builder.AddAppConfiguration(hostContext.HostingEnvironment.EnvironmentName, args); builder.AddAppConfiguration(hostContext.HostingEnvironment.EnvironmentName, args);
}) })
.ConfigureServices((context, services) =>
{
services.AddAppServices(context.Configuration);
})
.Build() .Build()
.Run(); .Run();
} }

57
src/Squidex/WebApp.cs → src/Squidex/WebStartup.cs

@ -6,6 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
@ -24,8 +25,10 @@ using Squidex.Infrastructure.Log;
namespace Squidex namespace Squidex
{ {
public static class WebApp public class WebStartup : IStartup
{ {
private readonly IConfiguration configuration;
private readonly IHostingEnvironment environment;
private static readonly string[] IdentityServerPaths = private static readonly string[] IdentityServerPaths =
{ {
"/client-callback-popup", "/client-callback-popup",
@ -34,42 +37,40 @@ namespace Squidex
"/error" "/error"
}; };
public static void ConfigureApp(this IApplicationBuilder app) public WebStartup(IConfiguration configuration, IHostingEnvironment environment)
{ {
var env = app.ApplicationServices.GetRequiredService<IHostingEnvironment>(); this.configuration = configuration;
this.environment = environment;
}
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddAppServices(configuration);
app.TestExternalSystems(); return services.BuildServiceProvider();
}
public void Configure(IApplicationBuilder app)
{
app.ApplicationServices.LogConfiguration();
app.ApplicationServices.TestExternalSystems();
app.UseMyCors(); app.UseMyCors();
app.UseMyForwardingRules(); app.UseMyForwardingRules();
app.UseMyTracking(); app.UseMyTracking();
app.MapAndUseIdentityServer(env); MapAndUseIdentityServer(app);
app.MapAndUseApi(env); MapAndUseApi(app);
app.MapAndUseFrontend(env); MapAndUseFrontend(app);
var log = app.ApplicationServices.GetRequiredService<ISemanticLog>();
var config = app.ApplicationServices.GetRequiredService<IConfiguration>();
log.LogInformation(w => w
.WriteProperty("message", "Application started")
.WriteObject("environment", c =>
{
foreach (var kvp in config.AsEnumerable().Where(kvp => kvp.Value != null))
{
c.WriteProperty(kvp.Key, kvp.Value);
}
}));
app.UseMyEventStore(); app.ApplicationServices.UseMyEventStore();
} }
private static void MapAndUseIdentityServer(this IApplicationBuilder app, IHostingEnvironment env) private void MapAndUseIdentityServer(IApplicationBuilder app)
{ {
app.Map(Constants.IdentityPrefix, identityApp => app.Map(Constants.IdentityPrefix, identityApp =>
{ {
if (env.IsDevelopment()) if (environment.IsDevelopment())
{ {
identityApp.UseDeveloperExceptionPage(); identityApp.UseDeveloperExceptionPage();
} }
@ -91,11 +92,11 @@ namespace Squidex
}); });
} }
private static void MapAndUseApi(this IApplicationBuilder app, IHostingEnvironment env) private void MapAndUseApi(IApplicationBuilder app)
{ {
app.Map(Constants.ApiPrefix, appApi => app.Map(Constants.ApiPrefix, appApi =>
{ {
if (env.IsDevelopment()) if (environment.IsDevelopment())
{ {
appApi.UseDeveloperExceptionPage(); appApi.UseDeveloperExceptionPage();
} }
@ -109,9 +110,9 @@ namespace Squidex
}); });
} }
private static void MapAndUseFrontend(this IApplicationBuilder app, IHostingEnvironment env) private void MapAndUseFrontend(IApplicationBuilder app)
{ {
if (env.IsDevelopment()) if (environment.IsDevelopment())
{ {
app.UseWebpackProxy(); app.UseWebpackProxy();
Loading…
Cancel
Save