Skip to content

Commit

Permalink
Merge pull request #774 from storybuilder-org/semantic_kernel
Browse files Browse the repository at this point in the history
Changes to expose ServiceCollection to Collaborator
PR APPROVED
  • Loading branch information
Rarisma authored Jul 24, 2024
2 parents b3bd3fb + 645aa44 commit 195e725
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 80 deletions.
12 changes: 10 additions & 2 deletions StoryCAD/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using StoryCAD.Services.IoC;
using StoryCAD.Services;
using StoryCAD.Services.Collaborator;
using Microsoft.Extensions.DependencyInjection;

namespace StoryCAD;

Expand Down Expand Up @@ -54,9 +55,16 @@ public partial class App
public App()
{
CheckForOtherInstances(); //Check other instances aren't already open.


ServiceLocator.Initialize();

// Build the service provider
var serviceProvider = ServiceLocator.Services.BuildServiceProvider();
// Configure the default IOC container
Ioc.Default.ConfigureServices(serviceProvider);

//Loads all Singletons/VMs
Ioc.Default.ConfigureServices(ServiceConfigurator.Configure());
//Ioc.Default.ConfigureServices(ServiceConfigurator.Configure());

string path = Path.Combine(Package.Current.InstalledLocation.Path, ".env");
DotEnvOptions options = new(false, new[] { path });
Expand Down
2 changes: 1 addition & 1 deletion StoryCADLib/Services/Collaborator/CollaboratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace StoryCAD.Services.Collaborator;
public class CollaboratorService
{
private bool dllExists;
private string dllPath;
private string dllPath;
private AppState State = Ioc.Default.GetRequiredService<AppState>();
private LogService logger = Ioc.Default.GetRequiredService<LogService>();
private WizardStepViewModel stepWizard;
Expand Down
75 changes: 0 additions & 75 deletions StoryCADLib/Services/IoC/ServiceConfigurator.cs

This file was deleted.

81 changes: 81 additions & 0 deletions StoryCADLib/Services/IoC/ServiceLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Microsoft.Extensions.DependencyInjection;
using StoryCAD.DAL;
using StoryCAD.Services.Backend;
using StoryCAD.Services.Backup;
using StoryCAD.Services.Navigation;
using StoryCAD.Services.Search;
using StoryCAD.ViewModels.Tools;
using StoryCAD.Collaborator.ViewModels;
using StoryCAD.Models.Tools;
using StoryCAD.Services.Collaborator;
using StoryCAD.Services.Ratings;

namespace StoryCAD.Services.IoC
{
public static class ServiceLocator
{
public static ServiceCollection Services { get; private set; }

static ServiceLocator()
{
Services = new ServiceCollection();
}

public static void Initialize()
{
Services.AddSingleton<NavigationService>();
Services.AddSingleton<LogService>();
Services.AddSingleton<SearchService>();
Services.AddSingleton<ControlLoader>();
Services.AddSingleton<ListLoader>();
Services.AddSingleton<ToolLoader>();
Services.AddSingleton<ScrivenerIo>();
Services.AddSingleton<StoryReader>();
Services.AddSingleton<StoryWriter>();
Services.AddSingleton<MySqlIo>();
Services.AddSingleton<BackupService>();
Services.AddSingleton<AutoSaveService>();
Services.AddSingleton<DeletionService>();
Services.AddSingleton<BackendService>();
Services.AddSingleton<CollaboratorService>();
Services.AddSingleton<ListData>();
Services.AddSingleton<ToolsData>();
Services.AddSingleton<ControlData>();
Services.AddSingleton<AppState>();
Services.AddSingleton<Windowing>();
Services.AddSingleton<RatingService>();
Services.AddSingleton<ShellViewModel>();
Services.AddSingleton<PreferenceService>();
Services.AddSingleton<OverviewViewModel>();
Services.AddSingleton<CharacterViewModel>();
Services.AddSingleton<ProblemViewModel>();
Services.AddSingleton<SettingViewModel>();
Services.AddSingleton<SceneViewModel>();
Services.AddSingleton<FolderViewModel>();
Services.AddSingleton<WebViewModel>();
Services.AddSingleton<WizardViewModel>();
Services.AddSingleton<WizardStepViewModel>();
Services.AddSingleton<TrashCanViewModel>();
Services.AddSingleton<UnifiedVM>();
Services.AddSingleton<InitVM>();
Services.AddSingleton<FeedbackViewModel>();
Services.AddSingleton<TreeViewSelection>();
// Register ContentDialog ViewModels
Services.AddSingleton<NewProjectViewModel>();
Services.AddSingleton<NewRelationshipViewModel>();
Services.AddSingleton<PrintReportDialogVM>();
Services.AddSingleton<NarrativeToolVM>();
Services.AddSingleton<ElementPickerVM>();
// Register Tools ViewModels
Services.AddSingleton<KeyQuestionsViewModel>();
Services.AddSingleton<TopicsViewModel>();
Services.AddSingleton<MasterPlotsViewModel>();
Services.AddSingleton<StockScenesViewModel>();
Services.AddSingleton<DramaticSituationsViewModel>();
Services.AddSingleton<SaveAsViewModel>();
Services.AddSingleton<PreferencesViewModel>();
Services.AddSingleton<FlawViewModel>();
Services.AddSingleton<TraitsViewModel>();
}
}
}
11 changes: 9 additions & 2 deletions StoryCADTests/IocLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using System.IO;
using StoryCAD.Services;
using Microsoft.Extensions.DependencyInjection;

namespace StoryCADTests
{
Expand All @@ -34,8 +35,14 @@ public static void Initialise(TestContext ctx)
{
if (!IocSetupComplete)
{
Ioc.Default.ConfigureServices(ServiceConfigurator.Configure());
IocSetupComplete = true;
ServiceLocator.Initialize();

// Build the service provider
var serviceProvider = ServiceLocator.Services.BuildServiceProvider();
// Configure the default IOC container
Ioc.Default.ConfigureServices(serviceProvider);

IocSetupComplete = true;
AppState State = Ioc.Default.GetService<AppState>();
PreferenceService Prefs = Ioc.Default.GetService<PreferenceService>();
Prefs.Model = new();
Expand Down

0 comments on commit 195e725

Please sign in to comment.