JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
563 stars 118 forks source link

Assembly scanning TheCallingAssembly works unpredictably #260

Open hahn-kev opened 3 years ago

hahn-kev commented 3 years ago

I just ran into an issue when using the assembly scanner where scan.TheCallingAssembly() worked differently depending on how the registry was used. Unfortunately it's hard to provide a simple reproduction since it requires 2 different projects to reproduce. But I'll provide an example of the issue.

Example:

Assembly.Core contains the following classes

Assembly.App contains the following:

my expectation is that both of the app registries work the same, however it turns out they don't because of how assembly scanning is implemented. When the inherit registry scanner runs it will only scan Assembly.App and not Assembly.Core where as when the Include registry uses the BaseRegistry directly then the scanner will scan Assembly.Core.

I ran into this issue when doing some refactoring of how we use registries, in some cases we were inheriting from a base registry and in others we were just calling include registry. I'd like to keep it consistent so I refactored our code to use include across the board, at that point I started getting weird errors as the scanner was now adding different services than it was before.

Taking a look at the code it looks like TheCallingAssembly has 2 paths implemented, one case it will determine the assembly based on the type of the registry, this means that the assembly will change if the registry is inherited from.

jeremydmiller commented 3 years ago

@hahn-kev, I don't think there's anything actionable here. If in doubt, explicitly specify the assembly by using a type, then saying "type.Assembly".

I'm just not enthusiastic about getting into this kind of inheritance with service registries.