using System.Reflection; using Autodesk.Revit.DB; using Microsoft.Extensions.DependencyInjection; using Speckle.Connectors.Common; using Speckle.Connectors.Common.Builders; using Speckle.Connectors.Common.Caching; using Speckle.Connectors.Common.Operations; using Speckle.Connectors.DUI; using Speckle.Connectors.DUI.Bindings; using Speckle.Connectors.DUI.Bridge; using Speckle.Connectors.Revit.Bindings; using Speckle.Connectors.Revit.HostApp; using Speckle.Connectors.Revit.Operations.Receive; using Speckle.Connectors.Revit.Operations.Receive.Settings; using Speckle.Connectors.Revit.Operations.Send; using Speckle.Connectors.Revit.Operations.Send.Settings; using Speckle.Connectors.Revit.Plugin; using Speckle.Converters.Common; using Speckle.Sdk; using Speckle.Sdk.Models.GraphTraversal; #if REVIT2026_OR_GREATER using Speckle.Connectors.Revit2026.Plugin; #else using CefSharp; #endif namespace Speckle.Connectors.Revit.DependencyInjection; // POC: should interface out things that are not public static class ServiceRegistration { public static void AddRevit(this IServiceCollection serviceCollection) { serviceCollection.AddConnectors(); serviceCollection.AddDUI(); RegisterUiDependencies(serviceCollection); serviceCollection.AddMatchingInterfacesAsTransient(Assembly.GetExecutingAssembly()); // Storage Schema serviceCollection.AddScoped(); serviceCollection.AddScoped(); // POC: we need to review the scopes and create a document on what the policy is // and where the UoW should be // register UI bindings serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(sp => sp.GetRequiredService()); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); // send operation and dependencies serviceCollection.AddScoped>(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped, RevitRootObjectBuilder>(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); // receive operation and dependencies serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddScoped(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(DefaultTraversal.CreateTraversalFunc()); serviceCollection.AddScoped(); // operation progress manager serviceCollection.AddSingleton(); } public static void RegisterUiDependencies(IServiceCollection serviceCollection) { #if REVIT2022 //different versons for different versions of CEF serviceCollection.AddSingleton(new BindingOptions() { CamelCaseJavascriptNames = false }); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(sp => sp.GetRequiredService()); serviceCollection.AddSingleton(); #elif !REVIT2026_OR_GREATER // different versions for different versions of CEF serviceCollection.AddSingleton(BindingOptions.DefaultBinder); var panel = new CefSharpPanel(); panel.Browser.JavascriptObjectRepository.NameConverter = null; serviceCollection.AddSingleton(panel); serviceCollection.AddSingleton(c => c.GetRequiredService()); serviceCollection.AddSingleton(); #else serviceCollection.AddSingleton(); serviceCollection.AddSingleton(c => c.GetRequiredService()); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); #endif } }