Skip to content

Commit

Permalink
#687 Guard against duplicate assemlbies
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Sampson committed Jun 4, 2020
1 parent 113f412 commit 0c4306a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
21 changes: 21 additions & 0 deletions src/Caliburn.Micro.Platform/AssemblySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ public static class AssemblySource
/// </summary>
public static readonly IObservableCollection<Assembly> Instance = new BindableCollection<Assembly>();


/// <summary>
/// Adds a collection of assemblies to AssemblySource
/// </summary>
/// <param name="assemblies">The assemblies to add</param>
public static void AddRange(IEnumerable<Assembly> assemblies)
{
foreach(var assembly in assemblies)
{
try
{
if (!Instance.Contains(assembly))
Instance.Add(assembly);
}
catch (ArgumentException)
{
// ignore
}
}
}

/// <summary>
/// Finds a type which matches one of the elements in the sequence of names.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CaliburnApplication(IntPtr javaReference, JniHandleOwnership transfer)
protected virtual void StartDesignTime()
{
AssemblySource.Instance.Clear();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

Configure();

Expand All @@ -45,7 +45,7 @@ protected virtual void StartDesignTime()
protected virtual void StartRuntime()
{
AssemblySourceCache.Install();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

Configure();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CaliburnApplicationDelegate(NSObjectFlag t)
protected virtual void StartDesignTime()
{
AssemblySource.Instance.Clear();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

Configure();

Expand All @@ -58,7 +58,7 @@ protected virtual void StartDesignTime()
protected virtual void StartRuntime()
{
AssemblySourceCache.Install();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

Configure();
IoC.GetInstance = GetInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void Initialize()
protected virtual void StartDesignTime()
{
AssemblySource.Instance.Clear();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

Configure();
IoC.GetInstance = GetInstance;
Expand All @@ -97,7 +97,7 @@ protected virtual void StartDesignTime()
protected virtual void StartRuntime()
{
AssemblySourceCache.Install();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

if (useApplication)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Caliburn.Micro.Platform/Platforms/net46/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void Initialize()
protected virtual void StartDesignTime()
{
AssemblySource.Instance.Clear();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

Configure();
IoC.GetInstance = GetInstance;
Expand All @@ -97,7 +97,7 @@ protected virtual void StartDesignTime()
protected virtual void StartRuntime()
{
AssemblySourceCache.Install();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

if (useApplication)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class CaliburnApplication : Application
protected virtual void StartDesignTime()
{
AssemblySource.Instance.Clear();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

Configure();
IoC.GetInstance = GetInstance;
Expand All @@ -42,7 +42,7 @@ protected virtual void StartDesignTime()
protected virtual void StartRuntime()
{
AssemblySourceCache.Install();
AssemblySource.Instance.AddRange(SelectAssemblies());
AssemblySource.AddRange(SelectAssemblies());

PrepareApplication();
Configure();
Expand Down

0 comments on commit 0c4306a

Please sign in to comment.