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

Constructor selection fails when using interception in one of the dependency graph #629

Closed
cervengoc opened this issue Sep 29, 2022 · 2 comments

Comments

@cervengoc
Copy link

Hi,

We'd like to ask for your help with the following issue.

  • Given a top-level service class TopLevelService having 2 dependencies
    • Required TopLevelServiceOptions
    • Optional IDependencyServiceIntercepted, implemented using constructor overloading
  • Given that IDependencyServiceIntercepted is intercepted using an interceptor
    • This is set up using a IContributeComponentModelConstruction
  • Given that everything is properly registered
  • When I resolve the TopLevelService...
  • Then it should use the constructor with 2 parameters, passing the resolved intercepted dependency service

But, instead, the library chooses the constructor having only the single TopLevelServiceOptions parameter.

As far as I could debug, the issue is that during resolution, the handler for IDependencyServiceIntercepted is still in WaitingDependencies state. If I'm not using the interceptor, the handler is in the proper Active state, and the resolution works as expected.

I've attached a simple console app reproducint the issue. It throws a NullReferenceException when it should not.

IssueWithConstructorOverloadAndInterception.zip

Thank you very much in advance for your support.

@jonorossi
Copy link
Member

A quick look at the code and I'd have thought it would work. The InterceptorInspector which converts InterceptorAttribute attributes uses IContributeComponentModelConstruction.

Does it work if you change the InterceptorReference to use the component type? i.e.:

model.Interceptors.Add(new InterceptorReference(typeof(TestInterceptor)));

I assume you're aware there is another extensibility point: IModelInterceptorsSelector.

@cervengoc
Copy link
Author

Hi @jonorossi ,

Thank you for your quick reply. First of all, sorry for the quality of the sample project, I've just now noticed that it doesn't even build, some refactoring has failed and also it was cut out from a solution where central package management was used.

Using the concrete type in the interceptor reference solves the issue, thank you.

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

No branches or pull requests

2 participants