Skip to content
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

Assembly scanning TheCallingAssembly works unpredictably #260

Open
hahn-kev opened this issue Sep 3, 2020 · 1 comment
Open

Assembly scanning TheCallingAssembly works unpredictably #260

hahn-kev opened this issue Sep 3, 2020 · 1 comment
Labels
question Further information is requested

Comments

@hahn-kev
Copy link

hahn-kev commented Sep 3, 2020

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

  • BaseRegistry : ServiceRegistry which which scans TheCallingAssembly and WithDefaultConventions
  • Service : IService both declared in this assembly

Assembly.App contains the following:

  • AppRegistryInherit : BaseRegistry doesn't scan anything
  • AppRegistryInclude : ServiceRegistry which just calls IncludeRegistry<BaseRegistry>()

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 jeremydmiller added the question Further information is requested label Nov 19, 2020
@jeremydmiller
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants