diff --git a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/ArcGISConverterModule.cs b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/ArcGISConverterModule.cs index 30a739310b..c9ea4f55a7 100644 --- a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/ArcGISConverterModule.cs +++ b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/ArcGISConverterModule.cs @@ -10,8 +10,13 @@ public class ArcGISConverterModule : ISpeckleModule { public void Load(SpeckleContainerBuilder builder) { + // add single root converter //don't need a host specific RootToSpeckleConverter - builder.AddConverterCommon(); + builder.AddRootCommon(); + + // add application converters + builder.AddApplicationConverters(); + // most things should be InstancePerLifetimeScope so we get one per operation builder.AddScoped(); builder.AddScoped(); diff --git a/DUI3-DX/Converters/Autocad/2023/Speckle.Converters.Autocad2023.DependencyInjection/AutocadConverterModule.cs b/DUI3-DX/Converters/Autocad/2023/Speckle.Converters.Autocad2023.DependencyInjection/AutocadConverterModule.cs index 375d2c8170..f37ac6541f 100644 --- a/DUI3-DX/Converters/Autocad/2023/Speckle.Converters.Autocad2023.DependencyInjection/AutocadConverterModule.cs +++ b/DUI3-DX/Converters/Autocad/2023/Speckle.Converters.Autocad2023.DependencyInjection/AutocadConverterModule.cs @@ -1,4 +1,4 @@ -using Autodesk.AutoCAD.ApplicationServices; +using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Speckle.Autofac.DependencyInjection; using Speckle.Converters.Autocad; @@ -11,9 +11,11 @@ public class AutocadConverterModule : ISpeckleModule { public void Load(SpeckleContainerBuilder builder) { - builder.AddConverterCommon(); + // add single root converter + builder.AddRootCommon(); - // single stack per conversion + // add application converters and context stack + builder.AddApplicationConverters(); builder.AddScoped, AutocadConversionContextStack>(); } } diff --git a/DUI3-DX/Converters/Autocad/2024/Speckle.Converters.Autocad2024.DependencyInjection/AutocadConverterModule.cs b/DUI3-DX/Converters/Autocad/2024/Speckle.Converters.Autocad2024.DependencyInjection/AutocadConverterModule.cs index 923bc241d1..66c4b57aff 100644 --- a/DUI3-DX/Converters/Autocad/2024/Speckle.Converters.Autocad2024.DependencyInjection/AutocadConverterModule.cs +++ b/DUI3-DX/Converters/Autocad/2024/Speckle.Converters.Autocad2024.DependencyInjection/AutocadConverterModule.cs @@ -11,9 +11,11 @@ public class AutocadConverterModule : ISpeckleModule { public void Load(SpeckleContainerBuilder builder) { - builder.AddConverterCommon(); + // add single root converter + builder.AddRootCommon(); - // single stack per conversion + // add application converters and context stack + builder.AddApplicationConverters(); builder.AddScoped, AutocadConversionContextStack>(); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs index f5211019ae..54203e1e03 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs @@ -12,7 +12,12 @@ public class RevitConverterModule : ISpeckleModule { public void Load(SpeckleContainerBuilder builder) { - builder.AddConverterCommon(); + // Register single root + builder.AddRootCommon(); + + // register all application converters + builder.AddApplicationConverters(); + builder.AddSingleton(new RevitContext()); // POC: do we need ToSpeckleScalingService as is, do we need to interface it out? diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoConverterModule.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoConverterModule.cs index 9117848c90..6cfca7fa5e 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoConverterModule.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoConverterModule.cs @@ -9,8 +9,11 @@ public class RhinoConverterModule : ISpeckleModule { public void Load(SpeckleContainerBuilder builder) { - builder.AddConverterCommon(); - // single stack per conversion + // Register single root + builder.AddRootCommon(); + + // register all application converters and context stacks + builder.AddApplicationConverters(); builder.AddScoped, RhinoConversionContextStack>(); } } diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs index 6a5fb37913..84ab8defe1 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs @@ -1,4 +1,4 @@ -using Speckle.Autofac.DependencyInjection; +using Speckle.Autofac.DependencyInjection; using Speckle.Converters.Common.DependencyInjection.ToHost; using Speckle.Converters.Common.Objects; @@ -6,14 +6,10 @@ namespace Speckle.Converters.Common.DependencyInjection; public static class ContainerRegistration { - public static void AddConverterCommon( - this SpeckleContainerBuilder builder - ) + public static void AddRootCommon(this SpeckleContainerBuilder builder) where TRootToSpeckleConverter : class, IRootToSpeckleConverter - where THostToSpeckleUnitConverter : class, IHostToSpeckleUnitConverter { builder.AddScoped(); - builder.AddScoped, THostToSpeckleUnitConverter>(); /* POC: CNX-9267 Moved the Injection of converters into the converter module. Not sure if this is 100% right, as this doesn't just register the conversions within this converter, but any conversions found in any Speckle.*.dll file. This will require consolidating across other connectors. @@ -29,8 +25,16 @@ This will require consolidating across other connectors. builder.AddScoped(); - builder.RegisterRawConversions(); builder.InjectNamedTypes(); builder.InjectNamedTypes(); } + + public static void AddApplicationConverters( + this SpeckleContainerBuilder builder + ) + where THostToSpeckleUnitConverter : class, IHostToSpeckleUnitConverter + { + builder.AddScoped, THostToSpeckleUnitConverter>(); + builder.RegisterRawConversions(); + } }