Skip to content

Commit 6964633

Browse files
romangolevjmcouffin
authored andcommitted
feat: replace DI architecture with plain intantiating of services. remove dependencies
1 parent ba7d564 commit 6964633

22 files changed

+81
-146
lines changed
Binary file not shown.
-2 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
-2 KB
Binary file not shown.
0 Bytes
Binary file not shown.

dev/pyRevitLoader/Source/PyRevitLoaderApplication.cs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
using System.Reflection;
44
using Autodesk.Revit.UI;
55
using Autodesk.Revit.Attributes;
6-
using Microsoft.Extensions.DependencyInjection;
7-
using Microsoft.Extensions.Logging;
86
using pyRevitAssemblyBuilder.AssemblyMaker;
97
using pyRevitAssemblyBuilder.SessionManager;
10-
using pyRevitAssemblyBuilder.Shared;
11-
using pyRevitAssemblyBuilder.Startup;
8+
using pyRevitAssemblyBuilder.FolderParser;
129

1310
/* Note:
1411
* It is necessary that this code object do not have any references to IronPython.
@@ -112,31 +109,21 @@ public static Result ExecuteStartUpCsharp(UIControlledApplication uiControlledAp
112109
var fi = uiControlledApplication.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
113110
var uiApplication = (UIApplication)fi.GetValue(uiControlledApplication);
114111

115-
var services = new ServiceCollection();
116-
services.AddLogging(cfg => cfg.AddDebug());
117-
118-
// Add Revit UIApplication to services
119-
services.AddSingleton(uiApplication);
120-
121-
// Add known services
122-
services.AddSingleton<ICommandTypeGenerator, DefaultCommandTypeGenerator>();
123-
services.AddSingleton<IHookManager, DummyHookManager>();
124-
services.AddSingleton<IUIManager, UIManagerService>();
125-
services.AddSingleton<ISessionManager, SessionManagerService>();
126-
services.AddSingleton<IExtensionManager, ExtensionManagerService>();
127-
128-
// Register AssemblyBuilderService with explicit string parameter
129-
services.AddSingleton<AssemblyBuilderService>(sp =>
130-
new AssemblyBuilderService(
131-
sp.GetRequiredService<ICommandTypeGenerator>(),
132-
versionNumber
133-
)
112+
// Instantiate all services
113+
var typeGenerator = new CommandTypeGenerator();
114+
var assemblyBuilder = new AssemblyBuilderService(typeGenerator, versionNumber);
115+
var extensionManager = new ExtensionManagerService();
116+
var hookManager = new HookManager();
117+
var uiManager = new UIManagerService(uiApplication);
118+
119+
var sessionManager = new SessionManagerService(
120+
assemblyBuilder,
121+
extensionManager,
122+
hookManager,
123+
uiManager
134124
);
135125

136-
var serviceProvider = services.BuildServiceProvider();
137-
var sessionManager = serviceProvider.GetRequiredService<ISessionManager>();
138-
sessionManager.LoadSessionAsync().Wait();
139-
126+
sessionManager.LoadSession();
140127
return Result.Succeeded;
141128
}
142129
catch (Exception ex)

dev/pyRevitLoader/pyRevitAssemblyBuilder/AssemblyMaker/AssemblyBuilderService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace pyRevitAssemblyBuilder.AssemblyMaker
88
{
99
public class AssemblyBuilderService
1010
{
11-
private readonly ICommandTypeGenerator _typeGenerator;
11+
private readonly CommandTypeGenerator _typeGenerator;
1212
private readonly string _revitVersion;
1313

14-
public AssemblyBuilderService(ICommandTypeGenerator typeGenerator, string revitVersion)
14+
public AssemblyBuilderService(CommandTypeGenerator typeGenerator, string revitVersion)
1515
{
1616
_typeGenerator = typeGenerator;
1717
_revitVersion = revitVersion ?? throw new ArgumentNullException(nameof(revitVersion));

dev/pyRevitLoader/pyRevitAssemblyBuilder/AssemblyMaker/DefaultCommandTypeGenerator.cs renamed to dev/pyRevitLoader/pyRevitAssemblyBuilder/AssemblyMaker/CommandTypeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace pyRevitAssemblyBuilder.AssemblyMaker
66
{
7-
public class DefaultCommandTypeGenerator : ICommandTypeGenerator
7+
public class CommandTypeGenerator
88
{
99
public void DefineCommandType(IExtension extension, ICommandComponent command, ModuleBuilder moduleBuilder)
1010
{

dev/pyRevitLoader/pyRevitAssemblyBuilder/AssemblyMaker/ICommandTypeGenerator.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)