Skip to content

Commit

Permalink
Simplify DI/assembly structure part deux (#270)
Browse files Browse the repository at this point in the history
* Rename utils to common

* fix namespaces

* Rhino kind of works

* Fix converter registration

* Fixed circular referece with lazy resolving

* Fixed Rhino8

* Revit 2022 builds

* revit 2023 compiles

* working on revit

* use speckle app for info instead of statics

* lazy init bindings

* Rhino compiles

* Revit compiles

* Autocad 2022 builds

* Autocad/Civil builds

* ArcGIS compiles

* Remove Autofac completely

* format

* React to SDK renames

* fixes for merge

* Update nuget and official sln

* Remove extra projects

* AutoActivate IBrowserBridge and rename it

* add extra null check

* Merge fixes

* Fix convertermanager problem and add tests

* Add new test project to local sln

* Use recursion

* formatting

* resolve circular dep with lazy get
adamhathcock authored Sep 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c805ff0 commit 3227d09
Showing 252 changed files with 3,753 additions and 10,622 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Mapping;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.Common.Cancellation;
using Speckle.Connectors.Common.Operations;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Logging;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.Utils.Cancellation;
using Speckle.Connectors.Utils.Operations;
using Speckle.Converters.ArcGIS3;
using Speckle.Converters.ArcGIS3.Utils;
using Speckle.Converters.Common;
@@ -21,19 +21,19 @@ public sealed class ArcGISReceiveBinding : IReceiveBinding
public string Name { get; } = "receiveBinding";
private readonly CancellationManager _cancellationManager;
private readonly DocumentModelStore _store;
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly IServiceProvider _serviceProvider;
private readonly IOperationProgressManager _operationProgressManager;
private readonly ILogger<ArcGISReceiveBinding> _logger;
private readonly IArcGISConversionSettingsFactory _arcGISConversionSettingsFactory;

private ReceiveBindingUICommands Commands { get; }
public IBridge Parent { get; }
public IBrowserBridge Parent { get; }

public ArcGISReceiveBinding(
DocumentModelStore store,
IBridge parent,
IBrowserBridge parent,
CancellationManager cancellationManager,
IUnitOfWorkFactory unitOfWorkFactory,
IServiceProvider serviceProvider,
IOperationProgressManager operationProgressManager,
ILogger<ArcGISReceiveBinding> logger,
IArcGISConversionSettingsFactory arcGisConversionSettingsFactory
@@ -43,7 +43,7 @@ IArcGISConversionSettingsFactory arcGisConversionSettingsFactory
_cancellationManager = cancellationManager;
Parent = parent;
Commands = new ReceiveBindingUICommands(parent);
_unitOfWorkFactory = unitOfWorkFactory;
_serviceProvider = serviceProvider;
_operationProgressManager = operationProgressManager;
_logger = logger;
_arcGISConversionSettingsFactory = arcGisConversionSettingsFactory;
@@ -61,9 +61,9 @@ public async Task Receive(string modelCardId)
}

CancellationToken cancellationToken = _cancellationManager.InitCancellationTokenSource(modelCardId);
using var unitOfWork = _unitOfWorkFactory.Create();
unitOfWork
.Resolve<IConverterSettingsStore<ArcGISConversionSettings>>()
using var scope = _serviceProvider.CreateScope();
scope
.ServiceProvider.GetRequiredService<IConverterSettingsStore<ArcGISConversionSettings>>()
.Initialize(
_arcGISConversionSettingsFactory.Create(
Project.Current,
@@ -72,8 +72,8 @@ public async Task Receive(string modelCardId)
)
);
// Receive host objects
var receiveOperationResults = await unitOfWork
.Resolve<ReceiveOperation>()
var receiveOperationResults = await scope
.ServiceProvider.GetRequiredService<ReceiveOperation>()
.Execute(
modelCard.GetReceiveInfo("ArcGIS"), // POC: get host app name from settings? same for GetSendInfo
cancellationToken,
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@ namespace Speckle.Connectors.ArcGIS.Bindings;
public class ArcGISSelectionBinding : ISelectionBinding
{
public string Name => "selectionBinding";
public IBridge Parent { get; }
public IBrowserBridge Parent { get; }

public ArcGISSelectionBinding(IBridge parent)
public ArcGISSelectionBinding(IBrowserBridge parent)
{
Parent = parent;
var topLevelHandler = parent.TopLevelExceptionHandler;
Original file line number Diff line number Diff line change
@@ -6,10 +6,12 @@
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Mapping.Events;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.ArcGIS.Filters;
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Cancellation;
using Speckle.Connectors.Common.Operations;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Exceptions;
@@ -18,9 +20,6 @@
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.Settings;
using Speckle.Connectors.Utils.Caching;
using Speckle.Connectors.Utils.Cancellation;
using Speckle.Connectors.Utils.Operations;
using Speckle.Converters.ArcGIS3;
using Speckle.Converters.ArcGIS3.Utils;
using Speckle.Converters.Common;
@@ -33,17 +32,16 @@ public sealed class ArcGISSendBinding : ISendBinding
{
public string Name => "sendBinding";
public SendBindingUICommands Commands { get; }
public IBridge Parent { get; }
public IBrowserBridge Parent { get; }

private readonly DocumentModelStore _store;
private readonly IUnitOfWorkFactory _unitOfWorkFactory; // POC: unused? :D
private readonly IServiceProvider _serviceProvider;
private readonly List<ISendFilter> _sendFilters;
private readonly CancellationManager _cancellationManager;
private readonly ISendConversionCache _sendConversionCache;
private readonly IOperationProgressManager _operationProgressManager;
private readonly ILogger<ArcGISSendBinding> _logger;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;
private readonly MapMembersUtils _mapMemberUtils;
private readonly IArcGISConversionSettingsFactory _arcGISConversionSettingsFactory;

/// <summary>
@@ -59,26 +57,24 @@ public sealed class ArcGISSendBinding : ISendBinding

public ArcGISSendBinding(
DocumentModelStore store,
IBridge parent,
IBrowserBridge parent,
IEnumerable<ISendFilter> sendFilters,
IUnitOfWorkFactory unitOfWorkFactory,
IServiceProvider serviceProvider,
CancellationManager cancellationManager,
ISendConversionCache sendConversionCache,
IOperationProgressManager operationProgressManager,
ILogger<ArcGISSendBinding> logger,
MapMembersUtils mapMemberUtils,
IArcGISConversionSettingsFactory arcGisConversionSettingsFactory
)
{
_store = store;
_unitOfWorkFactory = unitOfWorkFactory;
_serviceProvider = serviceProvider;
_sendFilters = sendFilters.ToList();
_cancellationManager = cancellationManager;
_sendConversionCache = sendConversionCache;
_operationProgressManager = operationProgressManager;
_logger = logger;
_topLevelExceptionHandler = parent.TopLevelExceptionHandler;
_mapMemberUtils = mapMemberUtils;
_arcGISConversionSettingsFactory = arcGisConversionSettingsFactory;

Parent = parent;
@@ -378,9 +374,9 @@ public async Task Send(string modelCardId)
var sendResult = await QueuedTask
.Run(async () =>
{
using var unitOfWork = _unitOfWorkFactory.Create();
unitOfWork
.Resolve<IConverterSettingsStore<ArcGISConversionSettings>>()
using var scope = _serviceProvider.CreateScope();
scope
.ServiceProvider.GetRequiredService<IConverterSettingsStore<ArcGISConversionSettings>>()
.Initialize(
_arcGISConversionSettingsFactory.Create(
Project.Current,
@@ -416,8 +412,8 @@ public async Task Send(string modelCardId)
}
}

var result = await unitOfWork
.Resolve<SendOperation<MapMember>>()
var result = await scope
.ServiceProvider.GetRequiredService<SendOperation<MapMember>>()
.Execute(
mapMembers,
modelCard.GetSendInfo("ArcGIS"), // POC: get host app name from settings? same for GetReceiveInfo
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.Utils.Common;
using Speckle.Sdk;
using Speckle.Sdk.Common;
using ArcProject = ArcGIS.Desktop.Core.Project;

@@ -16,14 +16,16 @@ namespace Speckle.Connectors.ArcGIS.Bindings;
public class BasicConnectorBinding : IBasicConnectorBinding
{
public string Name => "baseBinding";
public IBridge Parent { get; }
public IBrowserBridge Parent { get; }

public BasicConnectorBindingCommands Commands { get; }
private readonly DocumentModelStore _store;
private readonly ISpeckleApplication _speckleApplication;

public BasicConnectorBinding(DocumentModelStore store, IBridge parent)
public BasicConnectorBinding(DocumentModelStore store, IBrowserBridge parent, ISpeckleApplication speckleApplication)
{
_store = store;
_speckleApplication = speckleApplication;
Parent = parent;
Commands = new BasicConnectorBindingCommands(parent);

@@ -33,11 +35,11 @@ public BasicConnectorBinding(DocumentModelStore store, IBridge parent)
};
}

public string GetSourceApplicationName() => Speckle.Connectors.Utils.Connector.Slug;
public string GetSourceApplicationName() => _speckleApplication.Slug;

public string GetSourceApplicationVersion() => Speckle.Connectors.Utils.Connector.VersionString;
public string GetSourceApplicationVersion() => _speckleApplication.HostApplicationVersion;

public string GetConnectorVersion() => typeof(BasicConnectorBinding).Assembly.GetVersion();
public string GetConnectorVersion() => _speckleApplication.SpeckleVersion;

public DocumentInfo? GetDocumentInfo()
{
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
using ArcGIS.Desktop.Mapping;
using Autofac;
using Speckle.Autofac;
using Speckle.Autofac.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Connectors.ArcGIS.Bindings;
using Speckle.Connectors.ArcGIS.Filters;
using Speckle.Connectors.ArcGIS.HostApp;
using Speckle.Connectors.ArcGIS.Operations.Receive;
using Speckle.Connectors.ArcGis.Operations.Send;
using Speckle.Connectors.ArcGIS.Utils;
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.DUI.Models;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.WebView;
using Speckle.Connectors.Utils;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Caching;
using Speckle.Connectors.Utils.Operations;
using Speckle.Converters.Common;
using Speckle.Sdk.Models.GraphTraversal;

@@ -26,54 +23,47 @@

namespace Speckle.Connectors.ArcGIS.DependencyInjection;

public class ArcGISConnectorModule : ISpeckleModule
public static class ArcGISConnectorModule
{
public void Load(SpeckleContainerBuilder builder)
public static void AddArcGIS(this IServiceCollection serviceCollection)
{
builder.AddAutofac();
builder.AddConnectorUtils();
builder.AddDUI();
builder.AddDUIView();
serviceCollection.AddConnectorUtils();
serviceCollection.AddDUI();
serviceCollection.AddDUIView();

builder.AddSingleton<DocumentModelStore, ArcGISDocumentStore>();
serviceCollection.AddSingleton<DocumentModelStore, ArcGISDocumentStore>();
// Register bindings
builder.AddSingleton<IBinding, TestBinding>();
builder.AddSingleton<IBinding, ConfigBinding>("connectorName", "ArcGIS"); // POC: Easier like this for now, should be cleaned up later
builder.AddSingleton<IBinding, AccountBinding>();
serviceCollection.AddSingleton<IBinding, TestBinding>();
serviceCollection.AddSingleton<IBinding, ConfigBinding>();
serviceCollection.AddSingleton<IBinding, AccountBinding>();

builder.ContainerBuilder.RegisterType<TopLevelExceptionHandlerBinding>().As<IBinding>().AsSelf().SingleInstance();
builder.AddSingleton<ITopLevelExceptionHandler>(c =>
c.Resolve<TopLevelExceptionHandlerBinding>().Parent.TopLevelExceptionHandler
);
serviceCollection.RegisterTopLevelExceptionHandler();

builder
.ContainerBuilder.RegisterType<BasicConnectorBinding>()
.As<IBinding>()
.As<IBasicConnectorBinding>()
.SingleInstance();
serviceCollection.AddSingleton<IBinding>(sp => sp.GetRequiredService<IBasicConnectorBinding>());
serviceCollection.AddSingleton<IBasicConnectorBinding, BasicConnectorBinding>();

builder.AddSingleton<IBinding, ArcGISSelectionBinding>();
builder.AddSingleton<IBinding, ArcGISSendBinding>();
builder.AddSingleton<IBinding, ArcGISReceiveBinding>();
serviceCollection.AddSingleton<IBinding, ArcGISSelectionBinding>();
serviceCollection.AddSingleton<IBinding, ArcGISSendBinding>();
serviceCollection.AddSingleton<IBinding, ArcGISReceiveBinding>();

builder.AddTransient<ISendFilter, ArcGISSelectionFilter>();
builder.AddScoped<IHostObjectBuilder, ArcGISHostObjectBuilder>();
builder.AddSingleton(DefaultTraversal.CreateTraversalFunc());
serviceCollection.AddTransient<ISendFilter, ArcGISSelectionFilter>();
serviceCollection.AddScoped<IHostObjectBuilder, ArcGISHostObjectBuilder>();
serviceCollection.AddSingleton(DefaultTraversal.CreateTraversalFunc());

// register send operation and dependencies
builder.AddScoped<SendOperation<MapMember>>();
builder.AddScoped<ArcGISRootObjectBuilder>();
builder.AddScoped<IRootObjectBuilder<MapMember>, ArcGISRootObjectBuilder>();
serviceCollection.AddScoped<SendOperation<MapMember>>();
serviceCollection.AddScoped<ArcGISRootObjectBuilder>();
serviceCollection.AddScoped<IRootObjectBuilder<MapMember>, ArcGISRootObjectBuilder>();

builder.AddScoped<LocalToGlobalConverterUtils>();
serviceCollection.AddScoped<LocalToGlobalConverterUtils>();

builder.AddScoped<ArcGISColorManager>();
builder.AddScoped<MapMembersUtils>();
serviceCollection.AddScoped<ArcGISColorManager>();
serviceCollection.AddScoped<MapMembersUtils>();

// register send conversion cache
builder.AddSingleton<ISendConversionCache, SendConversionCache>();
serviceCollection.AddSingleton<ISendConversionCache, SendConversionCache>();

// operation progress manager
builder.AddSingleton<IOperationProgressManager, OperationProgressManager>();
serviceCollection.AddSingleton<IOperationProgressManager, OperationProgressManager>();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ArcGIS.Desktop.Framework.Threading.Tasks;
using Speckle.Connectors.Utils.Operations;
using Speckle.Connectors.Common.Operations;

namespace Speckle.Connectors.ArcGIS.HostApp;

Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@
using ArcGIS.Desktop.Mapping;
using Speckle.Connectors.ArcGIS.HostApp;
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Conversion;
using Speckle.Connectors.Utils.Instances;
using Speckle.Connectors.Utils.Operations;
using Speckle.Connectors.Common.Builders;
using Speckle.Connectors.Common.Conversion;
using Speckle.Connectors.Common.Instances;
using Speckle.Connectors.Common.Operations;
using Speckle.Converters.ArcGIS3;
using Speckle.Converters.ArcGIS3.Utils;
using Speckle.Converters.Common;
Original file line number Diff line number Diff line change
@@ -4,11 +4,11 @@
using Microsoft.Extensions.Logging;
using Speckle.Connectors.ArcGIS.HostApp;
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Caching;
using Speckle.Connectors.Utils.Conversion;
using Speckle.Connectors.Utils.Extensions;
using Speckle.Connectors.Utils.Operations;
using Speckle.Connectors.Common.Builders;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Conversion;
using Speckle.Connectors.Common.Extensions;
using Speckle.Connectors.Common.Operations;
using Speckle.Converters.ArcGIS3;
using Speckle.Converters.Common;
using Speckle.Objects.GIS;
Original file line number Diff line number Diff line change
@@ -27,9 +27,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Converters\ArcGIS\Speckle.Converters.ArcGIS3.DependencyInjection\Speckle.Converters.ArcGIS3.DependencyInjection.csproj" />
<ProjectReference Include="..\..\..\Converters\ArcGIS\Speckle.Converters.ArcGIS3\Speckle.Converters.ArcGIS3.csproj" />
<ProjectReference Include="..\..\..\DUI3\Speckle.Connectors.DUI.WebView\Speckle.Connectors.DUI.WebView.csproj" />
<ProjectReference Include="..\..\..\Sdk\Speckle.Connectors.Utils\Speckle.Connectors.Utils.csproj" />
<ProjectReference Include="..\..\..\Sdk\Speckle.Connectors.Common\Speckle.Connectors.Common.csproj" />
</ItemGroup>

<Import Project="Esri.ArcGISPro.Extensions30.Speckle.targets" />
Loading

0 comments on commit 3227d09

Please sign in to comment.