Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
44 changes: 39 additions & 5 deletions src/DynamoCore/Configuration/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,46 @@ struct PathManagerParams

internal class PathManager : IPathManager
{
internal static Lazy<PathManager>
lazy =
new Lazy<PathManager>
(() => new PathManager(new PathManagerParams()));
private static Lazy<PathManager> lazy;
Copy link
Member

@mjkkirschner mjkkirschner Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this implementation Lazy the docs say:
Use lazy initialization to defer the creation of a large or resource-intensive object, or the execution of a resource-intensive task, particularly when such creation or execution might not occur during the lifetime of the program.

I think it's unlikely any of our clients will not need a path manager.

If it was to make initialization thread safe, well then, this PR breaks that invariant, so whats the point?

private static readonly object lockObject = new object();

public static PathManager Instance { get { return lazy.Value; } }
/// <summary>
/// Initialize the PathManager singleton passing as a parameter a PathManagerParams object (which contains the Major and Minor version values).
/// </summary>
/// <param name="parameters"></param>
public static void Initialize(PathManagerParams parameters)
{
lock (lockObject)
{
if (lazy != null)
{
// Or do we want to reset the existing instance? See below for discussions.
throw new InvalidOperationException("PathManager has already been initialized.");
}

lazy = new Lazy<PathManager>(() => new PathManager(parameters));
}
}

public static PathManager Instance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments for public property please

{
get
{
if (lazy == null)
{
lock (lockObject)
{
if (lazy == null)
{
// Fallback to default if not initialized
lazy = new Lazy<PathManager>(() => new PathManager(new PathManagerParams()));
}
}
}

return lazy.Value;
}
}

#region Class Private Data Members

Expand Down
12 changes: 12 additions & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,18 @@ private void SearchModel_ItemProduced(NodeModel node)
/// <returns></returns>
internal PathManager CreatePathManager(IStartConfiguration config)
{
var pathManagerParams = new PathManagerParams();

var version = config.HostAnalyticsInfo.HostVersion;
if (version != null)
{
// Use host versions if provided
pathManagerParams.MajorFileVersion = version.Major;
pathManagerParams.MinorFileVersion = version.Minor;

Dynamo.Core.PathManager.Initialize(pathManagerParams);
}

if (!config.StartInTestMode)
{
if (!Core.PathManager.Instance.HasPathResolver)
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/DynamoInstallDetective/ProductLookUp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public static string GetDynamoPath(Version version, string debugPath = null)
if (installs == null) return string.Empty;

return installs.Products
.Where(p => p.VersionInfo.Item1 == version.Major)
.Where(p => p.VersionInfo.Item1 <= version.Major)
.Where(p => p.VersionInfo.Item2 >= version.Minor)
.Select(p => p.InstallLocation)
.LastOrDefault();
Expand Down
Loading