diff --git a/Hyperbar.Windows.Contextual/ContextualWidgetBuilder.cs b/Hyperbar.Windows.Contextual/ContextualWidgetBuilder.cs index 5a42114..09b09b0 100644 --- a/Hyperbar.Windows.Contextual/ContextualWidgetBuilder.cs +++ b/Hyperbar.Windows.Contextual/ContextualWidgetBuilder.cs @@ -1,15 +1,11 @@ -using Hyperbar.Lifecycles; using Microsoft.Extensions.DependencyInjection; -namespace Hyperbar.Extensions.Contextual; +namespace Hyperbar.Widget.Contextual; public class ContextualWidgetBuilder : IWidgetBuilder { - public void Create(IServiceCollection services) - { - services + public void Create(IServiceCollection services) => services .AddConfiguration() .AddWidgetTemplate(); - } } diff --git a/Hyperbar.Windows.Contextual/ContextualWidgetConfiguration.cs b/Hyperbar.Windows.Contextual/ContextualWidgetConfiguration.cs index 8531545..5187599 100644 --- a/Hyperbar.Windows.Contextual/ContextualWidgetConfiguration.cs +++ b/Hyperbar.Windows.Contextual/ContextualWidgetConfiguration.cs @@ -1,4 +1,4 @@ -namespace Hyperbar.Extensions.Contextual; +namespace Hyperbar.Widget.Contextual; public class ContextualWidgetConfiguration { diff --git a/Hyperbar.Windows.Contextual/ContextualWidgetViewModel.cs b/Hyperbar.Windows.Contextual/ContextualWidgetViewModel.cs index def5a46..170fe8d 100644 --- a/Hyperbar.Windows.Contextual/ContextualWidgetViewModel.cs +++ b/Hyperbar.Windows.Contextual/ContextualWidgetViewModel.cs @@ -1,11 +1,12 @@ -using Hyperbar.Lifecycles; -using Hyperbar.Templates; +namespace Hyperbar.Widget.Contextual; -namespace Hyperbar.Extensions.Contextual; - -public class ContextualWidgetViewModel(ITemplateFactory templateFactory) : - IWidgetViewModel, - ITemplatedViewModel +public class ContextualWidgetViewModel : + WidgetViewModelBase { - public ITemplateFactory TemplateFactory { get; } = templateFactory; -} + public ContextualWidgetViewModel(ITemplateFactory templateFactory, + IServiceFactory serviceFactory) : base(templateFactory, serviceFactory) + { + Add(); + Add(); + } +} \ No newline at end of file diff --git a/Hyperbar.Windows.Contextual/Hyperbar.Widget.Contextual.csproj b/Hyperbar.Windows.Contextual/Hyperbar.Widget.Contextual.csproj index 4291d89..4a8f052 100644 --- a/Hyperbar.Windows.Contextual/Hyperbar.Widget.Contextual.csproj +++ b/Hyperbar.Windows.Contextual/Hyperbar.Widget.Contextual.csproj @@ -1,21 +1,14 @@  - net8.0-windows10.0.19041.0 - 10.0.17763.0 - Hyperbar.Windows.Contextual - win10-x86;win10-x64;win10-arm64 - true + net8.0 true enable enable - - - diff --git a/Hyperbar.Windows.Primary/Hyperbar.Widget.Primary.csproj b/Hyperbar.Windows.Primary/Hyperbar.Widget.Primary.csproj index b855d21..4a8f052 100644 --- a/Hyperbar.Windows.Primary/Hyperbar.Widget.Primary.csproj +++ b/Hyperbar.Windows.Primary/Hyperbar.Widget.Primary.csproj @@ -9,6 +9,6 @@ - + diff --git a/Hyperbar.Windows.Primary/PrimaryWidgetBuilder.cs b/Hyperbar.Windows.Primary/PrimaryWidgetBuilder.cs index b3a0ae3..d25e082 100644 --- a/Hyperbar.Windows.Primary/PrimaryWidgetBuilder.cs +++ b/Hyperbar.Windows.Primary/PrimaryWidgetBuilder.cs @@ -1,4 +1,3 @@ -using Hyperbar.Lifecycles; using Microsoft.Extensions.DependencyInjection; namespace Hyperbar.Windows.Primary; @@ -6,10 +5,7 @@ namespace Hyperbar.Windows.Primary; public class PrimaryWidgetBuilder : IWidgetBuilder { - public void Create(IServiceCollection services) - { - services.AddConfiguration() - .AddTransient(); - } + public void Create(IServiceCollection services) => services.AddConfiguration() + .AddWidgetTemplate(); } diff --git a/Hyperbar.Windows.Primary/PrimaryWidgetViewModel.cs b/Hyperbar.Windows.Primary/PrimaryWidgetViewModel.cs index 54f5206..f508571 100644 --- a/Hyperbar.Windows.Primary/PrimaryWidgetViewModel.cs +++ b/Hyperbar.Windows.Primary/PrimaryWidgetViewModel.cs @@ -1,14 +1,19 @@ -using Hyperbar.Lifecycles; -using Hyperbar.Templates; - -namespace Hyperbar.Windows.Primary; +namespace Hyperbar.Windows.Primary; public class PrimaryWidgetViewModel : WidgetViewModelBase { - public PrimaryWidgetViewModel(ITemplateFactory templateFactory) : base(templateFactory) + public PrimaryWidgetViewModel(ITemplateFactory templateFactory, + IServiceFactory serviceFactory) : base(templateFactory, serviceFactory) { + ; + Add("test 1", new Action(() => { + + })); + Add("test 2", new Action(() => { })); + Add("test 4", new Action(() => { })); + Add("test 5", new Action(() => { })); } } diff --git a/Hyperbar.Windows/App.xaml.cs b/Hyperbar.Windows/App.xaml.cs index d4c870b..1016aaf 100644 --- a/Hyperbar.Windows/App.xaml.cs +++ b/Hyperbar.Windows/App.xaml.cs @@ -1,10 +1,10 @@ using Hyperbar.Windows.Controls; -using Hyperbar.Lifecycles; -using Hyperbar.Templates; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.UI.Xaml; +using Hyperbar.Widget.Contextual; +using Hyperbar.Windows.Primary; namespace Hyperbar.Windows; @@ -28,29 +28,30 @@ public partial class App : }) .ConfigureServices((context, services) => { + services.AddSingleton(provider => + new ServiceFactory((type, parameters) => ActivatorUtilities.CreateInstance(provider, type, parameters!))); + services.AddHostedService(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddContentTemplate(); - //services.AddCommand(""); - //services.AddWidget(""); + services.AddWidget(); + services.AddWidget(); services.AddTransient(provider => { static IEnumerable Resolve(IServiceProvider services) { - foreach (IWidgetContext commandContext in services.GetServices()) + foreach (IWidgetContext widgetContext in services.GetServices()) { - if (commandContext.ServiceProvider.GetService() is - IWidgetViewModel commandViewModel) + if (widgetContext.ServiceProvider.GetService() is + IWidgetViewModel viewModel) { - yield return commandViewModel; + yield return viewModel; } } } diff --git a/Hyperbar.Windows/Hyperbar.Windows.csproj b/Hyperbar.Windows/Hyperbar.Windows.csproj index e198d5c..a66a4fb 100644 --- a/Hyperbar.Windows/Hyperbar.Windows.csproj +++ b/Hyperbar.Windows/Hyperbar.Windows.csproj @@ -14,6 +14,9 @@ enable enable + + + @@ -38,6 +41,11 @@ + + + MSBuild:Compile + + true diff --git a/Hyperbar.Windows/Lifecycles/AppInitializer.cs b/Hyperbar.Windows/Lifecycles/AppInitializer.cs index afd5838..f61f4bb 100644 --- a/Hyperbar.Windows/Lifecycles/AppInitializer.cs +++ b/Hyperbar.Windows/Lifecycles/AppInitializer.cs @@ -1,7 +1,5 @@ using Hyperbar.Windows.Controls; -using Hyperbar.Lifecycles; using Microsoft.Extensions.DependencyInjection; -using System.Threading.Tasks; namespace Hyperbar.Windows; diff --git a/Hyperbar.Windows/Lifecycles/IServiceCollectionExtensions.cs b/Hyperbar.Windows/Lifecycles/IServiceCollectionExtensions.cs index 4b9daff..f6af132 100644 --- a/Hyperbar.Windows/Lifecycles/IServiceCollectionExtensions.cs +++ b/Hyperbar.Windows/Lifecycles/IServiceCollectionExtensions.cs @@ -1,14 +1,11 @@ -using Hyperbar.Lifecycles; -using Hyperbar.Templates; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace Hyperbar.Windows { public static class IServiceCollectionExtensions { - public static IServiceCollection AddWidget(this IServiceCollection services, - string key) + public static IServiceCollection AddWidget(this IServiceCollection services) where TCommandBuilder : IWidgetBuilder, new() { @@ -16,6 +13,12 @@ namespace Hyperbar.Windows IHost? host = new HostBuilder() .ConfigureServices(isolatedServices => { + isolatedServices.AddSingleton(provider => + new ServiceFactory((type, parameters) => ActivatorUtilities.CreateInstance(provider, type, parameters!))); + + isolatedServices.AddTransient(); + isolatedServices.AddContentTemplate(); + isolatedServices.AddTransient(); isolatedServices.AddTransient(); diff --git a/Hyperbar.Windows/Templates/TemplateFactory.cs b/Hyperbar.Windows/Templates/TemplateFactory.cs index 0f47a28..d04907f 100644 --- a/Hyperbar.Windows/Templates/TemplateFactory.cs +++ b/Hyperbar.Windows/Templates/TemplateFactory.cs @@ -1,10 +1,6 @@ -using Hyperbar.Templates; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using System; -using System.Collections.Generic; -using System.Linq; namespace Hyperbar.Windows; diff --git a/Hyperbar.Windows/Templates/TemplateGeneratorControl.cs b/Hyperbar.Windows/Templates/TemplateGeneratorControl.cs index ef3ca80..72efc22 100644 --- a/Hyperbar.Windows/Templates/TemplateGeneratorControl.cs +++ b/Hyperbar.Windows/Templates/TemplateGeneratorControl.cs @@ -1,5 +1,4 @@ -using Hyperbar.Templates; -using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; namespace Hyperbar.Windows; diff --git a/Hyperbar.Windows/Views/CommandViewModel.cs b/Hyperbar.Windows/Views/CommandViewModel.cs index b3d0718..1fd43a1 100644 --- a/Hyperbar.Windows/Views/CommandViewModel.cs +++ b/Hyperbar.Windows/Views/CommandViewModel.cs @@ -1,18 +1,15 @@ -using Hyperbar.Lifecycles; -using Hyperbar.Templates; -using System.Collections.Generic; - -namespace Hyperbar.Windows; +namespace Hyperbar.Windows; public partial class CommandViewModel : - ObservableCollectionViewModel, + ObservableCollectionViewModel, ITemplatedViewModel { - public CommandViewModel(ITemplateFactory templateFactory, - IEnumerable commands) + public CommandViewModel(ITemplateFactory templateFactory, + IServiceFactory serviceFactory, + IEnumerable widgets) : base(serviceFactory) { TemplateFactory = templateFactory; - AddRange(commands); + AddRange(widgets); } public ITemplateFactory TemplateFactory { get; } diff --git a/Hyperbar.Windows/Views/WidgetButtonView.xaml b/Hyperbar.Windows/Views/WidgetButtonView.xaml new file mode 100644 index 0000000..b7d76d9 --- /dev/null +++ b/Hyperbar.Windows/Views/WidgetButtonView.xaml @@ -0,0 +1,20 @@ + + + + + + + + + 32 + 32 + +