question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FromExecutingAssembly and FromCallingAssembly are misleading

See original GitHub issue

FromExecutingAssembly and FromCallingAssembly 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

        public IImplementationTypeSelector FromCallingAssembly()
        {
            return FromAssemblies(Assembly.GetCallingAssembly());
        }

        public IImplementationTypeSelector FromExecutingAssembly()
        {
            return FromAssemblies(Assembly.GetExecutingAssembly());
        }

Because these methods are defined in Scrutor, the resulting assemblies will be:

  • FromCallingAssembly will use the assembly that called Scrutor, rather than the actual calling assembly.
  • FromExecutingAssembly will use Scrutor’s assembly. Always.

In other words,

  • scan.FromCallingAssembly === scan.FromAssemblies(Assembly.GetExecutingAssembly())
  • scan.FromExecutingAssembly === scan.FromAssemblies(typeof(Scrutor).Assembly)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:9
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
MisinformedDNAcommented, Apr 21, 2021

Here’s my simple workaround:

services.Scan(s => s.FromAssemblies(Assembly.GetExecutingAssembly())
1reaction
MisinformedDNAcommented, Jul 13, 2023

Got stuck on this again. For CallingAssembly, I needed to do

var assembly = Assembly.GetCallingAssembly();
services.Scan(s => s.FromAssemblies(assembly));

Otherwise, the calling assembly ends up being Scrutor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImplementationTypeSelector.cs - khellang/Scrutor
Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection - Scrutor/src/Scrutor/ImplementationTypeSelector.cs at master ...
Read more >
Using Scrutor to automatically register your services with ...
In this post I describe how to use the open source library Scrutor to add assembly scanning capabilities to the ASP.NET Core DI...
Read more >
Scrutor - Bountysource
FromExecutingAssembly and FromCallingAssembly are misleading. The naming suggests that it will use the assemblies from the perspective of where it is being ...
Read more >
Why I don't use MediatR for CQRS
Looks like the naming of Scrutor methods is a little bit misleading. The problem is well-known and described here https://github.com/khellang...
Read more >
Using snake case column names with Dapper and PostgreSQL
In this post I'll discuss a technique I use occasionally to ensure that an ASP.NET Core app is able to start correctly, as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found