mirror of https://github.com/Squidex/squidex.git
35 changed files with 212 additions and 150 deletions
@ -0,0 +1,47 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Microsoft.Extensions.FileProviders; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment; |
||||
|
|
||||
|
namespace Squidex.Config.Orleans |
||||
|
{ |
||||
|
public sealed class EnvironmentWrapper : IHostingEnvironment |
||||
|
{ |
||||
|
private readonly IWebHostEnvironment nested; |
||||
|
|
||||
|
public string EnvironmentName |
||||
|
{ |
||||
|
get => nested.EnvironmentName; |
||||
|
set => nested.EnvironmentName = value; |
||||
|
} |
||||
|
|
||||
|
public string ApplicationName |
||||
|
{ |
||||
|
get => nested.ApplicationName; |
||||
|
set => nested.ApplicationName = value; |
||||
|
} |
||||
|
|
||||
|
public string ContentRootPath |
||||
|
{ |
||||
|
get => nested.ContentRootPath; |
||||
|
set => nested.ContentRootPath = value; |
||||
|
} |
||||
|
|
||||
|
public IFileProvider ContentRootFileProvider |
||||
|
{ |
||||
|
get => nested.ContentRootFileProvider; |
||||
|
set => nested.ContentRootFileProvider = value; |
||||
|
} |
||||
|
|
||||
|
public EnvironmentWrapper(IWebHostEnvironment nested) |
||||
|
{ |
||||
|
this.nested = nested; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,57 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System; |
|
||||
using Orleans; |
|
||||
using Orleans.ApplicationParts; |
|
||||
using Orleans.Configuration; |
|
||||
using Orleans.Hosting; |
|
||||
using OrleansDashboard; |
|
||||
using OrleansDashboard.Client; |
|
||||
using OrleansDashboard.Metrics; |
|
||||
using Squidex.Domain.Apps.Entities; |
|
||||
using Squidex.Infrastructure; |
|
||||
|
|
||||
namespace Squidex.Config.Orleans |
|
||||
{ |
|
||||
public static class Extensions |
|
||||
{ |
|
||||
public static void AddMyParts(this IApplicationPartManager builder) |
|
||||
{ |
|
||||
builder.AddApplicationPart(SquidexEntities.Assembly); |
|
||||
builder.AddApplicationPart(SquidexInfrastructure.Assembly); |
|
||||
} |
|
||||
|
|
||||
public static void Configure(this ClusterOptions options) |
|
||||
{ |
|
||||
options.ClusterId = Constants.OrleansClusterId; |
|
||||
options.ServiceId = Constants.OrleansClusterId; |
|
||||
} |
|
||||
|
|
||||
public static ISiloHostBuilder UseDashboardEx(this ISiloHostBuilder builder, Action<DashboardOptions> configurator = null) |
|
||||
{ |
|
||||
builder.AddStartupTask<Dashboard>(); |
|
||||
|
|
||||
builder.ConfigureApplicationParts(appParts => |
|
||||
appParts |
|
||||
.AddFrameworkPart(typeof(Dashboard).Assembly) |
|
||||
.AddFrameworkPart(typeof(DashboardClient).Assembly)); |
|
||||
|
|
||||
builder.ConfigureServices(services => |
|
||||
{ |
|
||||
services.AddDashboard(options => |
|
||||
{ |
|
||||
options.HostSelf = false; |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
builder.AddIncomingGrainCallFilter<GrainProfiler>(); |
|
||||
|
|
||||
return builder; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,73 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Orleans; |
||||
|
using Orleans.Hosting; |
||||
|
using Squidex.Infrastructure; |
||||
|
using HostingBuilderContext = Microsoft.Extensions.Hosting.HostBuilderContext; |
||||
|
using WebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment; |
||||
|
|
||||
|
namespace Squidex.Config.Orleans |
||||
|
{ |
||||
|
public sealed class SiloServiceBuilder : ISiloBuilder |
||||
|
{ |
||||
|
private readonly HostingBuilderContext context = new HostingBuilderContext(new Dictionary<object, object>()); |
||||
|
private readonly List<Action<HostingBuilderContext, ISiloBuilder>> configureSiloDelegates = new List<Action<HostingBuilderContext, ISiloBuilder>>(); |
||||
|
private readonly List<Action<HostingBuilderContext, IServiceCollection>> configureServicesDelegates = new List<Action<HostingBuilderContext, IServiceCollection>>(); |
||||
|
|
||||
|
public IDictionary<object, object> Properties |
||||
|
{ |
||||
|
get { return context.Properties; } |
||||
|
} |
||||
|
|
||||
|
public SiloServiceBuilder(IConfiguration config, WebHostEnvironment environment) |
||||
|
{ |
||||
|
context.Configuration = config; |
||||
|
context.HostingEnvironment = new EnvironmentWrapper(environment); |
||||
|
} |
||||
|
|
||||
|
public void Build(IServiceCollection serviceCollection) |
||||
|
{ |
||||
|
foreach (var configurationDelegate in configureSiloDelegates) |
||||
|
{ |
||||
|
configurationDelegate(context, this); |
||||
|
} |
||||
|
|
||||
|
serviceCollection.AddHostedService<SiloHost>(); |
||||
|
|
||||
|
this.ConfigureDefaults(); |
||||
|
this.ConfigureApplicationParts(parts => parts.ConfigureDefaults()); |
||||
|
|
||||
|
foreach (var configurationDelegate in configureServicesDelegates) |
||||
|
{ |
||||
|
configurationDelegate(context, serviceCollection); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public ISiloBuilder ConfigureSilo(Action<HostingBuilderContext, ISiloBuilder> configureDelegate) |
||||
|
{ |
||||
|
Guard.NotNull(configureDelegate, nameof(configureDelegate)); |
||||
|
|
||||
|
configureSiloDelegates.Add(configureDelegate); |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public ISiloBuilder ConfigureServices(Action<HostingBuilderContext, IServiceCollection> configureDelegate) |
||||
|
{ |
||||
|
Guard.NotNull(configureDelegate, nameof(configureDelegate)); |
||||
|
|
||||
|
configureServicesDelegates.Add(configureDelegate); |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue