-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
FromExecutingAssembly and FromCallingAssembly are misleading #92
Comments
Hmm. That's a very good point! 🤦♂️ The intention was to map directly to the I still think |
@khellang I agree, And you can make |
Hmm. There's definitely something weird going on here. I've made the following test app: using LibraryA;
using LibraryB;
using System;
using System.Reflection;
// In App.dll
namespace App
{
public static class Program
{
public static void Main(string[] args)
{
Console.WriteLine("App");
Console.WriteLine("Entry: " + Assembly.GetEntryAssembly());
Console.WriteLine("Executing: " + Assembly.GetExecutingAssembly());
Console.WriteLine("Calling: " + Assembly.GetCallingAssembly());
Console.WriteLine();
Console.WriteLine("Library A");
Console.WriteLine("Entry: " + A.GetEntryAssembly());
Console.WriteLine("Executing: " + A.GetExecutingAssembly());
Console.WriteLine("Calling: " + A.GetCallingAssembly());
Console.WriteLine();
Console.WriteLine("Entry (Transitive): " + A.TransitiveGetEntryAssembly());
Console.WriteLine("Executing (Transitive): " + A.TransitiveGetExecutingAssembly());
Console.WriteLine("Calling (Transitive): " + A.TransitiveGetCallingAssembly());
Console.WriteLine();
Console.WriteLine("Library B");
Console.WriteLine("Entry: " + B.GetEntryAssembly());
Console.WriteLine("Executing: " + B.GetExecutingAssembly());
Console.WriteLine("Calling: " + B.GetCallingAssembly());
}
}
}
// In LibraryA.dll
namespace LibraryA
{
public static class A
{
public static Assembly GetCallingAssembly() => Assembly.GetCallingAssembly();
public static Assembly GetExecutingAssembly() => Assembly.GetExecutingAssembly();
public static Assembly GetEntryAssembly() => Assembly.GetEntryAssembly();
public static Assembly TransitiveGetCallingAssembly() => B.GetCallingAssembly();
public static Assembly TransitiveGetExecutingAssembly() => B.GetExecutingAssembly();
public static Assembly TransitiveGetEntryAssembly() => B.GetEntryAssembly();
}
}
// In LibraryB.dll
namespace LibraryB
{
public class B
{
public static Assembly GetCallingAssembly() => Assembly.GetCallingAssembly();
public static Assembly GetExecutingAssembly() => Assembly.GetExecutingAssembly();
public static Assembly GetEntryAssembly() => Assembly.GetEntryAssembly();
}
} Which gives me the following result:
If you think of your app as |
I think the reason why
|
If I'm reading this correctly, you're saying that If so, it seems doubtful that inlining would occur under normal circumstances considering how scrutor is typically used, and in any case you certainly can't rely on it to occur. I don't see any way Scrutor could reliably provide a |
Yeah, at that point it's much better to just pass the returned assembly from |
I agree, |
Here's my simple workaround: services.Scan(s => s.FromAssemblies(Assembly.GetExecutingAssembly()) |
Got stuck on this again. For CallingAssembly, I needed to do
Otherwise, the calling assembly ends up being Scrutor. |
@khellang I was just reviewing Scrutor's recent releases and saw that |
FromExecutingAssembly
andFromCallingAssembly
are misleading. The naming suggests that it will use the assemblies from the perspective of where it is being called, but actually uses scrutor's perspective.https://github.com/khellang/Scrutor/blob/master/src/Scrutor/TypeSourceSelector.cs#L20
Because these methods are defined in Scrutor, the resulting assemblies will be:
In other words,
scan.FromCallingAssembly === scan.FromAssemblies(Assembly.GetExecutingAssembly())
scan.FromExecutingAssembly === scan.FromAssemblies(typeof(Scrutor).Assembly)
The text was updated successfully, but these errors were encountered: