start refactoring plugins
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using zero.Core.Plugins;
|
||||
|
||||
namespace zero.Core.Api
|
||||
{
|
||||
public class Plugins : ZeroPlugin, IPlugins
|
||||
{
|
||||
IEnumerable<ZeroPlugin> Items;
|
||||
|
||||
|
||||
public Plugins(IEnumerable<ZeroPlugin> plugins)
|
||||
{
|
||||
Items = plugins;
|
||||
|
||||
foreach (ZeroPlugin plugin in plugins)
|
||||
{
|
||||
Spaces.AddRange(plugin.Spaces);
|
||||
Features.AddRange(plugin.Features);
|
||||
PageTypes.AddRange(plugin.PageTypes);
|
||||
Permissions.AddRange(plugin.Permissions);
|
||||
Renderers.AddRange(plugin.Renderers);
|
||||
Sections.AddRange(plugin.Sections);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IPlugins
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,31 +9,12 @@ namespace zero.Core.Plugins
|
||||
{
|
||||
public abstract class ZeroPlugin
|
||||
{
|
||||
public SectionCollection Sections { get; private set; } = new SectionCollection();
|
||||
|
||||
public SpaceCollection Spaces { get; private set; } = new SpaceCollection();
|
||||
|
||||
public RendererCollection Renderers { get; private set; } = new RendererCollection();
|
||||
|
||||
public IList<SettingsGroup> Settings { get; private set; } = new List<SettingsGroup>();
|
||||
|
||||
public PermissionGroupCollection Permissions { get; private set; } = new PermissionGroupCollection();
|
||||
|
||||
public FeatureCollection Features { get; private set; } = new FeatureCollection();
|
||||
|
||||
public PageTypeCollection PageTypes { get; private set; } = new PageTypeCollection();
|
||||
|
||||
public IMapper Mapper { get; private set; }
|
||||
|
||||
protected virtual IServiceCollection ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
return services;
|
||||
}
|
||||
protected virtual void Configure(IServiceCollection services, IZeroPluginBuilder builder) { }
|
||||
}
|
||||
|
||||
|
||||
public interface IZeroPlugin
|
||||
{
|
||||
|
||||
void Configure(IServiceCollection services, IZeroPluginBuilder builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.Generic;
|
||||
using zero.Core.Entities;
|
||||
using zero.Core.Identity;
|
||||
using zero.Core.Mapper;
|
||||
|
||||
namespace zero.Core.Plugins
|
||||
{
|
||||
public class ZeroPluginBuilder : IZeroPluginBuilder
|
||||
{
|
||||
public SectionCollection Sections { get; private set; }
|
||||
|
||||
public SpaceCollection Spaces { get; private set; }
|
||||
|
||||
public RendererCollection Renderers { get; private set; };
|
||||
|
||||
public IList<SettingsGroup> Settings { get; private set; }
|
||||
|
||||
public PermissionGroupCollection Permissions { get; private set; }
|
||||
|
||||
public FeatureCollection Features { get; private set; }
|
||||
|
||||
public PageTypeCollection PageTypes { get; private set; }
|
||||
|
||||
public IMapper Mapper { get; private set; }
|
||||
|
||||
|
||||
public ZeroPluginBuilder(IMapper mapper)
|
||||
{
|
||||
Mapper = mapper;
|
||||
Sections = new SectionCollection();
|
||||
Spaces = new SpaceCollection();
|
||||
Renderers = new RendererCollection();
|
||||
Settings = new List<SettingsGroup>();
|
||||
Permissions = new PermissionGroupCollection();
|
||||
Features = new FeatureCollection();
|
||||
PageTypes = new PageTypeCollection();
|
||||
//Mapper = mapper;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IZeroPluginBuilder
|
||||
{
|
||||
SectionCollection Sections { get; }
|
||||
|
||||
SpaceCollection Spaces { get; }
|
||||
|
||||
RendererCollection Renderers { get; }
|
||||
|
||||
IList<SettingsGroup> Settings { get; }
|
||||
|
||||
PermissionGroupCollection Permissions { get; }
|
||||
|
||||
FeatureCollection Features { get; }
|
||||
|
||||
PageTypeCollection PageTypes { get; }
|
||||
|
||||
IMapper Mapper { get; }
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace zero.Core
|
||||
public string BackofficePath { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ZeroPlugin Backoffice { get; set; }
|
||||
public IZeroPlugin Backoffice { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,6 @@ namespace zero.Core
|
||||
/// <summary>
|
||||
/// Default settings for the backoffice
|
||||
/// </summary>
|
||||
ZeroPlugin Backoffice { get; set; }
|
||||
IZeroPlugin Backoffice { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace zero.Debug
|
||||
services.AddZero(Configuration)
|
||||
.AddPlugin<TestPlugin>()
|
||||
.AddPlugin<Test2Plugin>();
|
||||
|
||||
services.AddMvc();
|
||||
|
||||
services.Configure<IISOptions>(opts => opts.AutomaticAuthentication = false);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.Generic;
|
||||
using zero.Core.Entities;
|
||||
using zero.Core.Plugins;
|
||||
|
||||
namespace zero.TestData
|
||||
{
|
||||
public class Test2Plugin : ZeroPlugin
|
||||
public class Test2Plugin : IZeroPlugin
|
||||
{
|
||||
public Test2Plugin()
|
||||
public void Configure(IServiceCollection services, IZeroPluginBuilder builder)
|
||||
{
|
||||
PageTypes.Add(new PageType<NewsPage>()
|
||||
builder.PageTypes.Add(new PageType<NewsPage>()
|
||||
{
|
||||
Alias = "news",
|
||||
Name = "News",
|
||||
@@ -16,7 +17,7 @@ namespace zero.TestData
|
||||
Icon = "fth-book"
|
||||
});
|
||||
|
||||
PageTypes.Add(new PageType<ContentPage>()
|
||||
builder.PageTypes.Add(new PageType<ContentPage>()
|
||||
{
|
||||
Alias = "content",
|
||||
Name = "Page",
|
||||
@@ -25,7 +26,7 @@ namespace zero.TestData
|
||||
AllowAllChildrenTypes = true
|
||||
});
|
||||
|
||||
PageTypes.Add(new PageType<RedirectPage>()
|
||||
builder.PageTypes.Add(new PageType<RedirectPage>()
|
||||
{
|
||||
Alias = "redirect",
|
||||
Name = "Redirect",
|
||||
@@ -33,11 +34,11 @@ namespace zero.TestData
|
||||
AllowedChildrenTypes = new List<string>() { "content", "redirect" }
|
||||
});
|
||||
|
||||
Renderers.Add<OptionsPagePartial, OptionsPagePartialRenderer>();
|
||||
Renderers.Add<MetaPagePartial, MetaPagePartialRenderer>();
|
||||
Renderers.Add<NewsPage, NewsPageRenderer>();
|
||||
Renderers.Add<RedirectPage, RedirectPageRenderer>();
|
||||
Renderers.Add<ContentPage, ContentPageRenderer>();
|
||||
builder.Renderers.Add<OptionsPagePartial, OptionsPagePartialRenderer>();
|
||||
builder.Renderers.Add<MetaPagePartial, MetaPagePartialRenderer>();
|
||||
builder.Renderers.Add<NewsPage, NewsPageRenderer>();
|
||||
builder.Renderers.Add<RedirectPage, RedirectPageRenderer>();
|
||||
builder.Renderers.Add<ContentPage, ContentPageRenderer>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,23 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using zero.Core;
|
||||
using zero.Core.Entities;
|
||||
using zero.Core.Identity;
|
||||
using zero.Core.Plugins;
|
||||
using zero.TestData.Lists;
|
||||
|
||||
namespace zero.TestData
|
||||
{
|
||||
public class TestPlugin : ZeroPlugin
|
||||
public class TestPlugin : IZeroPlugin
|
||||
{
|
||||
public TestPlugin()
|
||||
public void Configure(IServiceCollection services, IZeroPluginBuilder builder)
|
||||
{
|
||||
Spaces.AddList<TeamMember>("team", "Team", "Our team members", "fth-users");
|
||||
Spaces.AddList<News>("news", "News", "Articles about the company", "fth-edit");
|
||||
Spaces.AddSeparator();
|
||||
Spaces.AddEditor<SocialContent>("social", "Social", "Links to social media", "fth-twitter");
|
||||
builder.Spaces.AddList<TeamMember>("team", "Team", "Our team members", "fth-users");
|
||||
builder.Spaces.AddList<News>("news", "News", "Articles about the company", "fth-edit");
|
||||
builder.Spaces.AddSeparator();
|
||||
builder.Spaces.AddEditor<SocialContent>("social", "Social", "Links to social media", "fth-twitter");
|
||||
|
||||
Features.Add(TestFeatures.Wishlist, "Wishlist", "Frontend wishlist for logged-in users");
|
||||
Features.Add(TestFeatures.SocialShopping, "Social shopping", "Integrate products into social media portals");
|
||||
builder.Features.Add(TestFeatures.Wishlist, "Wishlist", "Frontend wishlist for logged-in users");
|
||||
builder.Features.Add(TestFeatures.SocialShopping, "Social shopping", "Integrate products into social media portals");
|
||||
|
||||
Renderers.Add<TeamMember, TeamMemberRenderer>();
|
||||
Renderers.Add<SocialContent, SocialContentRenderer>();
|
||||
builder.Renderers.Add<TeamMember, TeamMemberRenderer>();
|
||||
builder.Renderers.Add<SocialContent, SocialContentRenderer>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
using zero.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using zero.Core;
|
||||
using zero.Core.Entities;
|
||||
using zero.Core.Plugins;
|
||||
using zero.Web.Sections;
|
||||
|
||||
namespace zero.Web
|
||||
{
|
||||
public class DefaultBackofficePlugin : ZeroPlugin
|
||||
public class DefaultBackofficePlugin : IZeroPlugin
|
||||
{
|
||||
public DefaultBackofficePlugin()
|
||||
public void Configure(IServiceCollection services, IZeroPluginBuilder builder)
|
||||
{
|
||||
Sections.Add<DashboardSection>();
|
||||
Sections.Add<PagesSection>();
|
||||
Sections.Add<SpacesSection>();
|
||||
Sections.Add<MediaSection>();
|
||||
Sections.Add<SettingsSection>();
|
||||
builder.Sections.Add<DashboardSection>();
|
||||
builder.Sections.Add<PagesSection>();
|
||||
builder.Sections.Add<SpacesSection>();
|
||||
builder.Sections.Add<MediaSection>();
|
||||
builder.Sections.Add<SettingsSection>();
|
||||
|
||||
SettingsGroup systemSettings = new SettingsGroup("@settings.groups.system");
|
||||
systemSettings.Add(Constants.Settings.Updates, "@settings.system.updates.name", "@settings.system.updates.text", "fth-check-circle");
|
||||
@@ -28,8 +29,8 @@ namespace zero.Web
|
||||
pluginSettings.Add(Constants.Settings.Plugins, "@settings.plugins.installed.name", "@settings.plugins.installed.text", "fth-package");
|
||||
pluginSettings.Add(Constants.Settings.CreatePlugin, "@settings.plugins.create.name", "@settings.plugins.create.text", "fth-box");
|
||||
|
||||
Settings.Add(systemSettings);
|
||||
Settings.Add(pluginSettings);
|
||||
builder.Settings.Add(systemSettings);
|
||||
builder.Settings.Add(pluginSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using zero.Core;
|
||||
using zero.Core.Extensions;
|
||||
using zero.Core.Plugins;
|
||||
|
||||
namespace zero.Web
|
||||
{
|
||||
|
||||
+23
-10
@@ -10,6 +10,7 @@ using Newtonsoft.Json.Serialization;
|
||||
using Raven.Client.Documents;
|
||||
using Raven.Client.Documents.Conventions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using zero.Core;
|
||||
using zero.Core.Api;
|
||||
@@ -39,23 +40,18 @@ namespace zero.Web
|
||||
Services = services;
|
||||
Configuration = configuration;
|
||||
|
||||
|
||||
|
||||
//CultureInfo cultureInfo = new CultureInfo("en-US");
|
||||
//cultureInfo.NumberFormat.CurrencySymbol = "€";
|
||||
//CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
|
||||
|
||||
AddConfiguration();
|
||||
|
||||
ConfgureMvc();
|
||||
ConfigureDatabase();
|
||||
ConfigureValidation();
|
||||
ConfigureMapper();
|
||||
ConfigureIdentity();
|
||||
|
||||
AddServices();
|
||||
|
||||
AddPlugin(x => x.GetService<IZeroOptions>().Backoffice);
|
||||
AddPlugins();
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +104,8 @@ namespace zero.Web
|
||||
Services.AddTransient<IPermissionsApi, PermissionsApi>();
|
||||
Services.AddTransient<IMediaApi, MediaApi>();
|
||||
Services.AddTransient<IMediaUpload, MediaUpload>();
|
||||
|
||||
Services.AddSingleton<IZeroPluginBuilder, ZeroPluginBuilder>();
|
||||
}
|
||||
|
||||
|
||||
@@ -254,6 +252,21 @@ namespace zero.Web
|
||||
}
|
||||
|
||||
|
||||
void AddPlugins()
|
||||
{
|
||||
AddPlugin(x => x.GetService<IZeroOptions>().Backoffice);
|
||||
|
||||
// build plugins
|
||||
//IEnumerable<IZeroPlugin> plugins = app.ApplicationServices.GetServices<IZeroPlugin>();
|
||||
//IZeroPluginBuilder pluginBuilder = app.ApplicationServices.GetService<IZeroPluginBuilder>();
|
||||
|
||||
//foreach (IZeroPlugin plugin in plugins)
|
||||
//{
|
||||
// plugin.Configure(app.ApplicationServices)
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Use specified options
|
||||
/// </summary>
|
||||
@@ -267,9 +280,9 @@ namespace zero.Web
|
||||
/// <summary>
|
||||
/// Adds a zero plugin
|
||||
/// </summary>
|
||||
public ZeroBuilder AddPlugin<T>() where T : ZeroPlugin
|
||||
public ZeroBuilder AddPlugin<T>() where T : class, IZeroPlugin
|
||||
{
|
||||
Services.AddTransient<ZeroPlugin, T>();
|
||||
Services.AddTransient<IZeroPlugin, T>();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -277,9 +290,9 @@ namespace zero.Web
|
||||
/// <summary>
|
||||
/// Adds a zero plugin
|
||||
/// </summary>
|
||||
public ZeroBuilder AddPlugin<T>(Func<IServiceProvider, T> implementationFactory) where T : ZeroPlugin
|
||||
public ZeroBuilder AddPlugin<T>(Func<IServiceProvider, T> implementationFactory) where T : class, IZeroPlugin
|
||||
{
|
||||
Services.AddTransient<ZeroPlugin, T>(implementationFactory);
|
||||
Services.AddTransient<IZeroPlugin, T>(implementationFactory);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user