Skip to content

Commit

Permalink
Better algorithm for selecting which assembly to load
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Nov 30, 2011
1 parent aab7fd1 commit 7f6f55e
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions Rhino.ServiceBus/Hosting/RemoteAppDomainHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,33 @@ public RemoteAppDomainHost(string assemblyPath, string configuration)
{
configurationFile = configuration;
assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
assemblyLocation = Path.GetDirectoryName(assemblyPath);
assemblyLocation = GetAssemblyLocation(assemblyPath);
}

protected string AssemblyName

private static string GetAssemblyLocation(string assemblyPath)
{
if (Path.IsPathRooted(assemblyPath))
return Path.GetDirectoryName(assemblyPath);

var currentDirPath = Path.Combine(Environment.CurrentDirectory, assemblyPath);
if (File.Exists(currentDirPath))
return Path.GetDirectoryName(currentDirPath);

var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyPath);
if (File.Exists(basePath))
return Path.GetDirectoryName(basePath);

// no idea, use the default
return Path.GetDirectoryName(assemblyPath);
}

protected string AssemblyName
{
get { return assemblyName; }
}

public IApplicationHost ApplicationHost { get { return current.ApplicationHost; } }

}

public IApplicationHost ApplicationHost { get { return current.ApplicationHost; } }

public void Start()
{
HostedService service = CreateNewAppDomain();
Expand Down Expand Up @@ -118,8 +135,8 @@ protected class HostedService
private readonly string assembly;
private readonly AppDomain appDomain;
private readonly ILog log = LogManager.GetLogger(typeof (HostedService));

public IApplicationHost ApplicationHost { get { return hoster; } }

public IApplicationHost ApplicationHost { get { return hoster; } }

public HostedService(IApplicationHost hoster, string assembly, AppDomain appDomain)
{
Expand Down Expand Up @@ -182,5 +199,5 @@ public RemoteAppDomainHost Configuration(string configFile)
configurationFile = configFile;
return this;
}
}
}
}

0 comments on commit 7f6f55e

Please sign in to comment.