Skip to content

Commit

Permalink
chore: use generic factory implementations
Browse files Browse the repository at this point in the history
Signed-off-by: russkyc <[email protected]>
  • Loading branch information
russkyc committed Jun 11, 2023
1 parent 1805a92 commit b10d06a
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 178 deletions.
16 changes: 0 additions & 16 deletions GroomWise.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9527855B-A10B-46BC-84CD-1FB1F68E191F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{6DF2E646-7D53-4C60-81F3-53D6A69B7AE0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Russkyc.GroomWise", "Russkyc.GroomWise\Russkyc.GroomWise.csproj", "{A82F86AC-0A28-486F-AB47-E62563AA7330}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Russkyc.GroomWise.Tests", "Russkyc.GroomWise.Tests\Russkyc.GroomWise.Tests.csproj", "{2D9EE5B5-7354-4524-88DB-BD2C4BF8C8E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Russkyc.GroomWise.Integration.Tests", "Russkyc.GroomWise.Integration.Tests\Russkyc.GroomWise.Integration.Tests.csproj", "{B53D7A17-0266-46BA-AD8D-49A64ADB69C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Russkyc.Groomwise.Cli", "Russkyc.Groomwise.Cli\Russkyc.Groomwise.Cli.csproj", "{0A95CE16-46C0-42B5-8EA9-C6B885D6ED49}"
EndProject
Global
Expand All @@ -19,23 +13,13 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A82F86AC-0A28-486F-AB47-E62563AA7330} = {9527855B-A10B-46BC-84CD-1FB1F68E191F}
{2D9EE5B5-7354-4524-88DB-BD2C4BF8C8E9} = {6DF2E646-7D53-4C60-81F3-53D6A69B7AE0}
{B53D7A17-0266-46BA-AD8D-49A64ADB69C0} = {6DF2E646-7D53-4C60-81F3-53D6A69B7AE0}
{0A95CE16-46C0-42B5-8EA9-C6B885D6ED49} = {9527855B-A10B-46BC-84CD-1FB1F68E191F}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A82F86AC-0A28-486F-AB47-E62563AA7330}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A82F86AC-0A28-486F-AB47-E62563AA7330}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A82F86AC-0A28-486F-AB47-E62563AA7330}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A82F86AC-0A28-486F-AB47-E62563AA7330}.Release|Any CPU.Build.0 = Release|Any CPU
{2D9EE5B5-7354-4524-88DB-BD2C4BF8C8E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D9EE5B5-7354-4524-88DB-BD2C4BF8C8E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D9EE5B5-7354-4524-88DB-BD2C4BF8C8E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D9EE5B5-7354-4524-88DB-BD2C4BF8C8E9}.Release|Any CPU.Build.0 = Release|Any CPU
{B53D7A17-0266-46BA-AD8D-49A64ADB69C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B53D7A17-0266-46BA-AD8D-49A64ADB69C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B53D7A17-0266-46BA-AD8D-49A64ADB69C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B53D7A17-0266-46BA-AD8D-49A64ADB69C0}.Release|Any CPU.Build.0 = Release|Any CPU
{0A95CE16-46C0-42B5-8EA9-C6B885D6ED49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A95CE16-46C0-42B5-8EA9-C6B885D6ED49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A95CE16-46C0-42B5-8EA9-C6B885D6ED49}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public record AppointmentServiceProduct
public virtual Product Product { get; set; }

[Navigate(nameof(ServiceId))]
public virtual GroomingService GroomingService { get; set; }
public virtual AppointmentService AppointmentService { get; set; }
}
36 changes: 22 additions & 14 deletions Russkyc.GroomWise/Models/Helper/WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,44 @@ namespace GroomWise.Models.Helper;
public static class WindowHelper
{
public static T AsChild<T>(this T child)
where T : Window
where T : class
{
child.Owner = (ModernWindow)BuilderServices.Resolve<IMainView>();
child.WindowStartupLocation = WindowStartupLocation.CenterOwner;
child.ShowInTaskbar = false;
var view = child as Window;
view.Owner = (ModernWindow)BuilderServices.Resolve<IMainView>();
view.WindowStartupLocation = WindowStartupLocation.CenterOwner;
view.ShowInTaskbar = false;
child = view as T;
return child;
}

public static T AddParent<T>(this T child, Window parent)
where T : Window
where T : class
{
child.Owner = parent;
child.WindowStartupLocation = WindowStartupLocation.CenterOwner;
child.ShowInTaskbar = false;
var view = child as Window;
view.Owner = parent;
view.WindowStartupLocation = WindowStartupLocation.CenterOwner;
view.ShowInTaskbar = false;
child = view as T;
return child;
}

public static T ExitOnParentMouseDown<T>(this T child)
where T : Window
where T : class
{
child.Owner.MouseDown += (s, e) => child.Close();
child.Owner.PreviewMouseDown += (s, e) => child.Close();
var view = child as Window;
view.Owner.MouseDown += (s, e) => view.Close();
view.Owner.PreviewMouseDown += (s, e) => view.Close();
child = view as T;
return child;
}

public static T HideOnParentMouseDown<T>(this T child)
where T : Window
where T : class
{
child.Owner.MouseDown += (s, e) => child.Hide();
child.Owner.PreviewMouseDown += (s, e) => child.Hide();
var view = child as Window;
view.Owner.MouseDown += (s, e) => view.Hide();
view.Owner.PreviewMouseDown += (s, e) => view.Hide();
child = view as T;
return child;
}
}
2 changes: 1 addition & 1 deletion Russkyc.GroomWise/Russkyc.GroomWise.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<PackageReference Include="NETCore.Encrypt" Version="2.1.1" />
<PackageReference Include="Russkyc.Abstractions" Version="1.6.1" />
<PackageReference Include="Russkyc.AttachedUtilities.FilestreamExtensions" Version="1.1.1" />
<PackageReference Include="Russkyc.DependencyInjection" Version="0.9.7" />
<PackageReference Include="Russkyc.DependencyInjection" Version="0.9.8" />
<PackageReference Include="Russkyc.ModernControls.WPF" Version="1.9.18" />
<PackageReference Include="Russkyc.Services.HotKeyListener" Version="0.11.1" />
<PackageReference Include="Swordfish.NET.CollectionsV3" Version="3.3.12" />
Expand Down
21 changes: 0 additions & 21 deletions Russkyc.GroomWise/Services/Factory/AddAppointmentsViewFactory.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Russkyc.GroomWise/Services/Factory/AppointmentFactory.cs

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions Russkyc.GroomWise/Services/Factory/CustomerFactory.cs

This file was deleted.

18 changes: 0 additions & 18 deletions Russkyc.GroomWise/Services/Factory/DialogFactory.cs

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions Russkyc.GroomWise/Services/Factory/EmployeeFactory.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

namespace GroomWise.Services.Factory;

public class AccountFactory : Factory<Account> { }
public class GenericFactory<T> : Factory<T>
where T : class { }
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@

namespace GroomWise.Services.Factory;

public class CustomerCardViewModelFactory : Factory<CustomerCardViewModel> { }
public class InjectorFactory<T> : Factory<T>
where T : class
{
public new T Create(Action<T> builder = null)
{
T instance = (BuilderServices.Resolve(typeof(T)) as T)!;
builder?.Invoke(instance);
return instance;
}
}
8 changes: 0 additions & 8 deletions Russkyc.GroomWise/Services/Factory/MaterialIconFactory.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Russkyc.GroomWise/Services/Factory/NavItemFactory.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Russkyc.GroomWise/Services/Factory/NotificationFactory.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Russkyc.GroomWise/Services/Factory/RoleFactory.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Russkyc.GroomWise/Services/Factory/SessionFactory.cs

This file was deleted.

27 changes: 13 additions & 14 deletions Russkyc.GroomWise/Services/ServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ public static IServicesContainer ConfigureServices()
// Add Logger
.AddSingleton<ILogger, DebugAndFileLogger>()
// Add Factory Services
.AddSingleton<IFactory<AppointmentService>, AppointmentServiceFactory>()
.AddSingleton<IFactory<AddAppointmentsView>, AddAppointmentsViewFactory>()
.AddSingleton<IFactory<CustomerCardViewModel>, CustomerCardViewModelFactory>()
.AddSingleton<IFactory<EmployeeCardViewModel>, EmployeeCardViewModelFactory>()
.AddSingleton<IFactory<MaterialIcon>, MaterialIconFactory>()
.AddSingleton<IFactory<Notification>, NotificationFactory>()
.AddSingleton<IFactory<Appointment>, AppointmentFactory>()
.AddSingleton<IFactory<Customer>, CustomerFactory>()
.AddSingleton<IFactory<Employee>, EmployeeFactory>()
.AddSingleton<IFactory<NavItem>, NavItemFactory>()
.AddSingleton<IFactory<Account>, AccountFactory>()
.AddSingleton<IFactory<DialogView>, DialogFactory>()
.AddSingleton<IFactory<Pet>, PetFactory>()
.AddSingleton<IFactory<Session>, SessionFactory>()
.AddSingleton<IFactory<AppointmentService>, GenericFactory<AppointmentService>>()
.AddSingleton<IFactory<CustomerCardViewModel>, GenericFactory<CustomerCardViewModel>>()
.AddSingleton<IFactory<EmployeeCardViewModel>, GenericFactory<EmployeeCardViewModel>>()
.AddSingleton<IFactory<DialogView>, GenericFactory<DialogView>>()
.AddSingleton<IFactory<MaterialIcon>, GenericFactory<MaterialIcon>>()
.AddSingleton<IFactory<Notification>, GenericFactory<Notification>>()
.AddSingleton<IFactory<Appointment>, GenericFactory<Appointment>>()
.AddSingleton<IFactory<Customer>, GenericFactory<Customer>>()
.AddSingleton<IFactory<Employee>, GenericFactory<Employee>>()
.AddSingleton<IFactory<NavItem>, GenericFactory<NavItem>>()
.AddSingleton<IFactory<Account>, GenericFactory<Account>>()
.AddSingleton<IFactory<Session>, GenericFactory<Session>>()
.AddSingleton<IFactory<Pet>, GenericFactory<Pet>>()
// Add Data Services
.AddSingleton<IConnectionSourceProvider, ConnectionSourceProvider>()
.AddSingleton<IDatabaseServiceAsync, DataServiceProviderAsync>()
Expand Down
2 changes: 1 addition & 1 deletion Russkyc.GroomWise/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
global using GroomWise.ViewModels.Inventory;
global using GroomWise.ViewModels.Services;
global using GroomWise.Services;
global using GroomWise.Services.Factory;
global using GroomWise.Services.App;
global using GroomWise.Services.Data;
global using GroomWise.Services.Factory;
global using GroomWise.Services.Repository;
2 changes: 2 additions & 0 deletions Russkyc.GroomWise/ViewModels/App/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private async void Logout()
DialogFactory
.Create(dialog =>
{
dialog.AsChild();
dialog.HideOnParentMouseDown();
dialog.MessageBoxText = "Are you sure?";
dialog.Caption = "Do you want to log out? You can log back in anytime.";
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public partial class AppointmentsViewModel : ViewModelBase, IAppointmentsViewMod
{
private readonly ILogger _logger;
private readonly ISchedulerService _schedulerService;
private readonly IFactory<AddAppointmentsView> _addAppointmentsViewFactory;

private readonly IUnitOfWork _dbContext;

Expand All @@ -19,14 +18,12 @@ public partial class AppointmentsViewModel : ViewModelBase, IAppointmentsViewMod
public AppointmentsViewModel(
ILogger logger,
IUnitOfWork dbContext,
ISchedulerService schedulerService,
IFactory<AddAppointmentsView> addAppointmentsViewFactory
ISchedulerService schedulerService
)
{
_logger = logger;
_dbContext = dbContext;
_schedulerService = schedulerService;
_addAppointmentsViewFactory = addAppointmentsViewFactory;

Appointments = new SynchronizedObservableCollection<Appointment>();

Expand Down Expand Up @@ -54,8 +51,9 @@ void GetAppointments()
[RelayCommand]
void AddAppointment()
{
_addAppointmentsViewFactory
.Create()
BuilderServices.Resolve<IAddAppointmentsView>()
.AsChild()
.HideOnParentMouseDown()
.Show();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (C) 2023 Russell Camo (Russkyc).- All Rights Reserved
//
//
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

namespace GroomWise.Services.Factory;
namespace GroomWise.ViewModels.Employees;

public class PetFactory : Factory<Pet> { }
public class AddEmployeesViewmodel
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public partial class AddAppointmentsView : IAddAppointmentsView
public AddAppointmentsView(IAddAppointmentsViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
}

public void ClearFields()
Expand Down

0 comments on commit b10d06a

Please sign in to comment.