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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use speckle app for info instead of statics
adamhathcock committed Sep 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6991bf854c692f137724cfba15240b6d41412dde
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Sdk;
using Speckle.Sdk.Common;
using ArcProject = ArcGIS.Desktop.Core.Project;
using Connector = Speckle.Connectors.Common.Connector;
@@ -21,10 +22,12 @@ public class BasicConnectorBinding : IBasicConnectorBinding

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

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

@@ -34,11 +37,11 @@ public BasicConnectorBinding(DocumentModelStore store, IBridge parent)
};
}

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

public string GetSourceApplicationVersion() => Connector.VersionString;
public string GetSourceApplicationVersion() => _speckleApplication.Application;

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
@@ -19,7 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\Converters\Revit\Speckle.Converters.Revit2025.DependencyInjection\Speckle.Converters.Revit2025.DependencyInjection.csproj" />
<ProjectReference Include="..\..\..\Converters\Revit\Speckle.Converters.Revit2025\Speckle.Converters.Revit2025.csproj" />
<ProjectReference Include="..\..\..\DUI3\Speckle.Connectors.DUI.WebView\Speckle.Connectors.DUI.WebView.csproj" />
<ProjectReference Include="..\..\..\DUI3\Speckle.Connectors.DUI\Speckle.Connectors.DUI.csproj" />
<ProjectReference Include="..\..\..\Sdk\Speckle.Converters.Common.DependencyInjection\Speckle.Converters.Common.DependencyInjection.csproj" />
<ProjectReference Include="..\..\..\Sdk\Speckle.Converters.Common\Speckle.Converters.Common.csproj" />
<ProjectReference Include="..\..\..\Sdk\Speckle.Connectors.Common\Speckle.Connectors.Common.csproj" />
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System.Reflection;
using Autodesk.Revit.DB;
using Revit.Async;
using Speckle.Connectors.Common.Common;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.RevitShared;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Sdk;
using Speckle.Sdk.Common;
using Connector = Speckle.Connectors.Common.Connector;

namespace Speckle.Connectors.DUI.Bindings;

@@ -23,13 +20,15 @@ internal sealed class BasicConnectorBindingRevit : IBasicConnectorBinding

private readonly DocumentModelStore _store;
private readonly RevitContext _revitContext;
private readonly ISpeckleApplication _speckleApplication;

public BasicConnectorBindingRevit(DocumentModelStore store, IBridge parent, RevitContext revitContext)
public BasicConnectorBindingRevit(DocumentModelStore store, IBridge parent, RevitContext revitContext, ISpeckleApplication speckleApplication)
{
Name = "baseBinding";
Parent = parent;
_store = store;
_revitContext = revitContext;
_speckleApplication = speckleApplication;
Commands = new BasicConnectorBindingCommands(parent);

// POC: event binding?
@@ -39,12 +38,11 @@ public BasicConnectorBindingRevit(DocumentModelStore store, IBridge parent, Revi
};
}

public string GetConnectorVersion() => Assembly.GetAssembly(GetType()).NotNull().GetVersion();
public string GetConnectorVersion() => _speckleApplication.SpeckleVersion;

public string GetSourceApplicationName() => Connector.Slug.ToLower(); // POC: maybe not right place but... // ANOTHER POC: We should align this naming from somewhere in common DUI projects instead old structs. I know there are other POC comments around this

public string GetSourceApplicationVersion() => Connector.VersionString; // POC: maybe not right place but...
public string GetSourceApplicationName() => _speckleApplication.Slug;

public string GetSourceApplicationVersion() => _speckleApplication.AppVersion;
public DocumentInfo? GetDocumentInfo()
{
// POC: not sure why this would ever be null, is this needed?
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Speckle.Connectors.Common;
using Speckle.Connectors.Common.Builders;
using Speckle.Connectors.Common.Cancellation;
using Speckle.Connectors.Common.Operations;
@@ -26,6 +25,7 @@ internal sealed class RevitReceiveBinding : IReceiveBinding
private readonly DocumentModelStore _store;
private readonly IServiceProvider _serviceProvider;
private readonly IRevitConversionSettingsFactory _revitConversionSettingsFactory;
private readonly ISpeckleApplication _speckleApplication;
private ReceiveBindingUICommands Commands { get; }

public RevitReceiveBinding(
@@ -35,15 +35,15 @@ public RevitReceiveBinding(
IServiceProvider serviceProvider,
IOperationProgressManager operationProgressManager,
ILogger<RevitReceiveBinding> logger,
IRevitConversionSettingsFactory revitConversionSettingsFactory
)
IRevitConversionSettingsFactory revitConversionSettingsFactory, ISpeckleApplication speckleApplication)
{
Parent = parent;
_store = store;
_serviceProvider = serviceProvider;
_operationProgressManager = operationProgressManager;
_logger = logger;
_revitConversionSettingsFactory = revitConversionSettingsFactory;
_speckleApplication = speckleApplication;
_cancellationManager = cancellationManager;

Commands = new ReceiveBindingUICommands(parent);
@@ -77,7 +77,7 @@ public async Task Receive(string modelCardId)
HostObjectBuilderResult conversionResults = await scope
.ServiceProvider.GetRequiredService<ReceiveOperation>()
.Execute(
modelCard.GetReceiveInfo(Connector.Slug),
modelCard.GetReceiveInfo(_speckleApplication.Slug),
cancellationToken,
(status, progress) =>
_operationProgressManager.SetModelProgress(
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
using Speckle.Converters.RevitShared.Settings;
using Speckle.Sdk;
using Speckle.Sdk.Common;
using Connector = Speckle.Connectors.Common.Connector;

namespace Speckle.Connectors.Revit.Bindings;

@@ -36,6 +35,7 @@ internal sealed class RevitSendBinding : RevitBaseBinding, ISendBinding
private readonly ILogger<RevitSendBinding> _logger;
private readonly ElementUnpacker _elementUnpacker;
private readonly IRevitConversionSettingsFactory _revitConversionSettingsFactory;
private readonly ISpeckleApplication _speckleApplication;

/// <summary>
/// Used internally to aggregate the changed objects' id. Note we're using a concurrent dictionary here as the expiry check method is not thread safe, and this was causing problems. See:
@@ -57,8 +57,7 @@ public RevitSendBinding(
ToSpeckleSettingsManager toSpeckleSettingsManager,
ILogger<RevitSendBinding> logger,
ElementUnpacker elementUnpacker,
IRevitConversionSettingsFactory revitConversionSettingsFactory
)
IRevitConversionSettingsFactory revitConversionSettingsFactory, ISpeckleApplication speckleApplication)
: base("sendBinding", store, bridge, revitContext)
{
_idleManager = idleManager;
@@ -70,6 +69,7 @@ IRevitConversionSettingsFactory revitConversionSettingsFactory
_logger = logger;
_elementUnpacker = elementUnpacker;
_revitConversionSettingsFactory = revitConversionSettingsFactory;
_speckleApplication = speckleApplication;
var topLevelExceptionHandler = Parent.TopLevelExceptionHandler;

Commands = new SendBindingUICommands(bridge);
@@ -140,7 +140,7 @@ public async Task Send(string modelCardId)
.ServiceProvider.GetRequiredService<SendOperation<ElementId>>()
.Execute(
revitObjects,
modelCard.GetSendInfo(Connector.Slug),
modelCard.GetSendInfo(_speckleApplication.Slug),
(status, progress) =>
_operationProgressManager.SetModelProgress(
Parent,
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Reflection;
using Autodesk.Revit.UI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Speckle.Connectors.Common;
using Speckle.Connectors.Common.Common;
using Speckle.Connectors.Revit.DependencyInjection;
using Speckle.Converters.RevitShared;
using Speckle.Sdk;
@@ -42,9 +44,10 @@ public Result OnStartup(UIControlledApplication application)
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver.OnAssemblyResolve<RevitExternalApplication>;
var services = new ServiceCollection();
// init DI
_disposableLogger = services.Initialize(HostApplications.Revit, GetVersion());
_disposableLogger = services.Initialize(HostApplications.Revit, GetVersion(), Assembly.GetExecutingAssembly().GetVersion());
services.AddRevit();
services.AddRevitConverters();
services.AddSingleton(application);
_container = services.BuildServiceProvider();

// resolve root object
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.Rhino.Extensions;
using Speckle.Sdk;
using Speckle.Sdk.Common;

namespace Speckle.Connectors.Rhino.Bindings;
@@ -19,11 +20,13 @@ public class RhinoBasicConnectorBinding : IBasicConnectorBinding
public BasicConnectorBindingCommands Commands { get; }

private readonly DocumentModelStore _store;
private readonly ISpeckleApplication _speckleApplication;

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

_store.DocumentChanged += (_, _) =>
@@ -32,11 +35,11 @@ public RhinoBasicConnectorBinding(DocumentModelStore store, IBridge parent)
};
}

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

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

public string GetSourceApplicationVersion() => "7";
public string GetSourceApplicationVersion() => _speckleApplication.AppVersion;

public DocumentInfo? GetDocumentInfo()
{
19 changes: 5 additions & 14 deletions Sdk/Speckle.Connectors.Common/Connector.cs
Original file line number Diff line number Diff line change
@@ -15,27 +15,18 @@ public static class Connector
public static readonly string TabName = "Speckle";
public static readonly string TabTitle = "Speckle (Beta)";

public static HostAppVersion Version { get; private set; } = HostAppVersion.v3;
public static string VersionString { get; private set; } = string.Empty;
public static string Name => HostApp.Name;
public static string Slug => HostApp.Slug;

public static HostApplication HostApp { get; private set; }

public static IDisposable? Initialize(
this IServiceCollection serviceCollection,
HostApplication application,
HostAppVersion version
HostAppVersion version,
string speckleVersion
)
{
Version = version;
VersionString = HostApplications.GetVersion(version);
HostApp = application;
TypeLoader.Initialize(typeof(Base).Assembly, typeof(Point).Assembly);

var (logging, tracing) = Observability.Initialize(
VersionString,
Slug,
application.Slug,
HostApplications.GetVersion(version),
Assembly.GetExecutingAssembly().GetVersion(),
new(
new SpeckleLogging(
@@ -57,7 +48,7 @@ HostAppVersion version
);

serviceCollection.AddLogging(x => x.AddProvider(new SpeckleLogProvider(logging)));
serviceCollection.AddSpeckleSdk(application, version);
serviceCollection.AddSpeckleSdk(application, version, speckleVersion);
serviceCollection.AddSingleton<Speckle.Sdk.Logging.ISdkActivityFactory, ConnectorActivityFactory>();
return tracing;
}