diff --git a/zero.Core/Api/Plugins.cs b/zero.Core/Api/Plugins.cs deleted file mode 100644 index 8275824c..00000000 --- a/zero.Core/Api/Plugins.cs +++ /dev/null @@ -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 Items; - - - public Plugins(IEnumerable 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 - { - - } -} diff --git a/zero.Core/Plugins/ZeroPlugin.cs b/zero.Core/Plugins/ZeroPlugin.cs index 6fd5371a..69749ba8 100644 --- a/zero.Core/Plugins/ZeroPlugin.cs +++ b/zero.Core/Plugins/ZeroPlugin.cs @@ -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 Settings { get; private set; } = new List(); - - 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); } -} +} \ No newline at end of file diff --git a/zero.Core/Plugins/ZeroPluginBuilder.cs b/zero.Core/Plugins/ZeroPluginBuilder.cs new file mode 100644 index 00000000..ac15c0b6 --- /dev/null +++ b/zero.Core/Plugins/ZeroPluginBuilder.cs @@ -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 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(); + Permissions = new PermissionGroupCollection(); + Features = new FeatureCollection(); + PageTypes = new PageTypeCollection(); + //Mapper = mapper; + } + } + + + public interface IZeroPluginBuilder + { + SectionCollection Sections { get; } + + SpaceCollection Spaces { get; } + + RendererCollection Renderers { get; } + + IList Settings { get; } + + PermissionGroupCollection Permissions { get; } + + FeatureCollection Features { get; } + + PageTypeCollection PageTypes { get; } + + IMapper Mapper { get; } + } +} diff --git a/zero.Core/ZeroOptions.cs b/zero.Core/ZeroOptions.cs index 9ebbb404..62b71f5c 100644 --- a/zero.Core/ZeroOptions.cs +++ b/zero.Core/ZeroOptions.cs @@ -31,7 +31,7 @@ namespace zero.Core public string BackofficePath { get; set; } /// - public ZeroPlugin Backoffice { get; set; } + public IZeroPlugin Backoffice { get; set; } } @@ -79,6 +79,6 @@ namespace zero.Core /// /// Default settings for the backoffice /// - ZeroPlugin Backoffice { get; set; } + IZeroPlugin Backoffice { get; set; } } } diff --git a/zero.Debug/Startup.cs b/zero.Debug/Startup.cs index 784a06b3..626b89ec 100644 --- a/zero.Debug/Startup.cs +++ b/zero.Debug/Startup.cs @@ -38,6 +38,7 @@ namespace zero.Debug services.AddZero(Configuration) .AddPlugin() .AddPlugin(); + services.AddMvc(); services.Configure(opts => opts.AutomaticAuthentication = false); diff --git a/zero.Debug/TestData/Test2Plugin.cs b/zero.Debug/TestData/Test2Plugin.cs index fd920f16..dead0845 100644 --- a/zero.Debug/TestData/Test2Plugin.cs +++ b/zero.Debug/TestData/Test2Plugin.cs @@ -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() + builder.PageTypes.Add(new PageType() { Alias = "news", Name = "News", @@ -16,7 +17,7 @@ namespace zero.TestData Icon = "fth-book" }); - PageTypes.Add(new PageType() + builder.PageTypes.Add(new PageType() { Alias = "content", Name = "Page", @@ -25,7 +26,7 @@ namespace zero.TestData AllowAllChildrenTypes = true }); - PageTypes.Add(new PageType() + builder.PageTypes.Add(new PageType() { Alias = "redirect", Name = "Redirect", @@ -33,11 +34,11 @@ namespace zero.TestData AllowedChildrenTypes = new List() { "content", "redirect" } }); - Renderers.Add(); - Renderers.Add(); - Renderers.Add(); - Renderers.Add(); - Renderers.Add(); + builder.Renderers.Add(); + builder.Renderers.Add(); + builder.Renderers.Add(); + builder.Renderers.Add(); + builder.Renderers.Add(); } } } diff --git a/zero.Debug/TestData/TestPlugin.cs b/zero.Debug/TestData/TestPlugin.cs index 61f7defc..9548855e 100644 --- a/zero.Debug/TestData/TestPlugin.cs +++ b/zero.Debug/TestData/TestPlugin.cs @@ -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("team", "Team", "Our team members", "fth-users"); - Spaces.AddList("news", "News", "Articles about the company", "fth-edit"); - Spaces.AddSeparator(); - Spaces.AddEditor("social", "Social", "Links to social media", "fth-twitter"); + builder.Spaces.AddList("team", "Team", "Our team members", "fth-users"); + builder.Spaces.AddList("news", "News", "Articles about the company", "fth-edit"); + builder.Spaces.AddSeparator(); + builder.Spaces.AddEditor("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(); - Renderers.Add(); + builder.Renderers.Add(); + builder.Renderers.Add(); } } } diff --git a/zero.Web/DefaultBackofficePlugin.cs b/zero.Web/DefaultBackofficePlugin.cs index 6c0ebc36..5b2ff209 100644 --- a/zero.Web/DefaultBackofficePlugin.cs +++ b/zero.Web/DefaultBackofficePlugin.cs @@ -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(); - Sections.Add(); - Sections.Add(); - Sections.Add(); - Sections.Add(); + builder.Sections.Add(); + builder.Sections.Add(); + builder.Sections.Add(); + builder.Sections.Add(); + builder.Sections.Add(); 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); } } } diff --git a/zero.Web/ZeroApplicationBuilderExtensions.cs b/zero.Web/ZeroApplicationBuilderExtensions.cs index 450fefad..320baa21 100644 --- a/zero.Web/ZeroApplicationBuilderExtensions.cs +++ b/zero.Web/ZeroApplicationBuilderExtensions.cs @@ -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 { diff --git a/zero.Web/ZeroBuilder.cs b/zero.Web/ZeroBuilder.cs index 10d74c21..c80a36a0 100644 --- a/zero.Web/ZeroBuilder.cs +++ b/zero.Web/ZeroBuilder.cs @@ -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().Backoffice); + AddPlugins(); } @@ -108,6 +104,8 @@ namespace zero.Web Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + + Services.AddSingleton(); } @@ -254,6 +252,21 @@ namespace zero.Web } + void AddPlugins() + { + AddPlugin(x => x.GetService().Backoffice); + + // build plugins + //IEnumerable plugins = app.ApplicationServices.GetServices(); + //IZeroPluginBuilder pluginBuilder = app.ApplicationServices.GetService(); + + //foreach (IZeroPlugin plugin in plugins) + //{ + // plugin.Configure(app.ApplicationServices) + //} + } + + /// /// Use specified options /// @@ -267,9 +280,9 @@ namespace zero.Web /// /// Adds a zero plugin /// - public ZeroBuilder AddPlugin() where T : ZeroPlugin + public ZeroBuilder AddPlugin() where T : class, IZeroPlugin { - Services.AddTransient(); + Services.AddTransient(); return this; } @@ -277,9 +290,9 @@ namespace zero.Web /// /// Adds a zero plugin /// - public ZeroBuilder AddPlugin(Func implementationFactory) where T : ZeroPlugin + public ZeroBuilder AddPlugin(Func implementationFactory) where T : class, IZeroPlugin { - Services.AddTransient(implementationFactory); + Services.AddTransient(implementationFactory); return this; } }