diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/IWidgetDefinitionProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/IWidgetDefinitionProvider.cs new file mode 100644 index 0000000000..f1f94f7e09 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/IWidgetDefinitionProvider.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets +{ + public interface IWidgetDefinitionProvider + { + List GetDefinitions(); + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs index 0b74fa9e07..2296cfb4e4 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs @@ -24,7 +24,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets private ILocalizableString _displayName; [NotNull] - public Type ViewComponentType { get; set; } + public Type ViewComponentType { get; } [CanBeNull] public WidgetDimensions DefaultDimensions { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetOptionsExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetOptionsExtensions.cs new file mode 100644 index 0000000000..a723b56b68 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetOptionsExtensions.cs @@ -0,0 +1,13 @@ +namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets +{ + public static class WidgetOptionsExtensions + { + public static void AddWidgets(this WidgetOptions options) + where T : IWidgetDefinitionProvider, new() + { + var provider = new T(); + var widgets = provider.GetDefinitions(); + options.Widgets.AddRange(widgets); + } + } +} diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/DashboardDemoWebModule.cs b/samples/DashboardDemo/src/DashboardDemo.Web/DashboardDemoWebModule.cs index dd52df853e..3e71e5f7da 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/DashboardDemoWebModule.cs +++ b/samples/DashboardDemo/src/DashboardDemo.Web/DashboardDemoWebModule.cs @@ -84,8 +84,7 @@ namespace DashboardDemo { Configure(options => { - options.Widgets.Add(new WidgetDefinition("MyWidget", typeof(MyWidgetViewComponentModel), - new LocalizableString(typeof(DashboardDemoResource), "MyWidgett"))); + options.AddWidgets(); }); } diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/WidgetDefinitionProvider.cs b/samples/DashboardDemo/src/DashboardDemo.Web/WidgetDefinitionProvider.cs new file mode 100644 index 0000000000..1bc238e40c --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/WidgetDefinitionProvider.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using DashboardDemo.Localization.DashboardDemo; +using DashboardDemo.Pages.widgets; +using Volo.Abp.AspNetCore.Mvc.UI.Widgets; +using Volo.Abp.Localization; + +namespace DashboardDemo +{ + public class WidgetDefinitionProvider : IWidgetDefinitionProvider + { + public List GetDefinitions() + { + var widgets = new List(); + + var myWidget = new WidgetDefinition("MyWidget", typeof(MyWidgetViewComponentModel), + new LocalizableString(typeof(DashboardDemoResource), "MyWidgett")); + + widgets.Add(myWidget); + + return widgets; + } + } +}