Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify DI assembly structure #256

Merged
merged 27 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e6fca46
Rename utils to common
adamhathcock Sep 18, 2024
4f6e21b
fix namespaces
adamhathcock Sep 18, 2024
5399a08
Rhino kind of works
adamhathcock Sep 19, 2024
bd4c2aa
Merge remote-tracking branch 'origin/dev' into adam/cxpla-15-simplify…
adamhathcock Sep 19, 2024
b8d14bd
Fix converter registration
adamhathcock Sep 19, 2024
70ea70b
Fixed circular referece with lazy resolving
adamhathcock Sep 19, 2024
0e1ef58
Fixed Rhino8
adamhathcock Sep 19, 2024
5a1ba02
Revit 2022 builds
adamhathcock Sep 19, 2024
a1f5085
revit 2023 compiles
adamhathcock Sep 19, 2024
0b52a6e
working on revit
adamhathcock Sep 19, 2024
6991bf8
use speckle app for info instead of statics
adamhathcock Sep 19, 2024
661e899
lazy init bindings
adamhathcock Sep 19, 2024
aca1439
Rhino compiles
adamhathcock Sep 19, 2024
b083596
Revit compiles
adamhathcock Sep 19, 2024
cbee823
Autocad 2022 builds
adamhathcock Sep 19, 2024
a129c79
Autocad/Civil builds
adamhathcock Sep 19, 2024
53d6194
ArcGIS compiles
adamhathcock Sep 19, 2024
40134c5
Remove Autofac completely
adamhathcock Sep 19, 2024
ae32d97
format
adamhathcock Sep 19, 2024
75b3747
React to SDK renames
adamhathcock Sep 19, 2024
628af3d
Merge remote-tracking branch 'origin/dev' into adam/cxpla-15-simplify…
adamhathcock Sep 19, 2024
594bf88
fixes for merge
adamhathcock Sep 19, 2024
2790484
Update nuget and official sln
adamhathcock Sep 20, 2024
e90ad4a
Remove extra projects
adamhathcock Sep 20, 2024
d837cb5
AutoActivate IBrowserBridge and rename it
adamhathcock Sep 20, 2024
9a899c7
add extra null check
adamhathcock Sep 20, 2024
70b4f64
Merge branch 'dev' into adam/cxpla-15-simplify-assembly-structure
adamhathcock Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Expand All @@ -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
Expand All @@ -43,7 +43,7 @@ IArcGISConversionSettingsFactory arcGisConversionSettingsFactory
_cancellationManager = cancellationManager;
Parent = parent;
Commands = new ReceiveBindingUICommands(parent);
_unitOfWorkFactory = unitOfWorkFactory;
_serviceProvider = serviceProvider;
_operationProgressManager = operationProgressManager;
_logger = logger;
_arcGISConversionSettingsFactory = arcGisConversionSettingsFactory;
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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>
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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()
{
Expand Down
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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Loading
Loading