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.

AutoCrossWireFrameworkComponents not working as expected

See original GitHub issue

Describe the bug

According to the documentation (and code) AutoCrossWireFrameworkComponents should be true by default. However we experience the need to manually cross-wire stuff from MS.DI to SimpleInjector. As mentioned in the code in #936 IHttpContextAccessor does not seem to be cross wired automatically. Recently we made some changes to our internal Http package (moving away from RestSharp and into using IHttpClientFactory). It now looks like this needs manual cross-wiring as well.

Expected behavior

Unless setting AutoCrossWireFrameworkComponents to false I would think that cross-wiring is handled automatically.

Actual behavior

In our Azure Functions Integration package we have the following code:

services.AddSimpleInjector(Container, options =>
{
    // Prevent the use of hosted services (not supported by Azure Functions).
    options.EnableHostedServiceResolution = false;

    // Allow injecting ILogger into application components
    options.AddLogging();

    // Somehow the Asp.NetCore IHttpContextAccessor is not available internally in our 
    // SimpleInjector container unless we explicitly cross-wire it. 
    options.CrossWire<IHttpContextAccessor>();
});

trying to get any instance from the container using the updated internal Http package (called HttpClient) we get the following error:

SimpleInjector.ActivationException The configuration is invalid. Creating the instance for type IRequestHandler<GetReconciliationResultByReleaseGroupRequest, ReconciliationResult> failed. The constructor of type HttpClient contains the parameter with name ‘httpClientFactory’ and type IHttpClientFactory, but IHttpClientFactory is not registered. For IHttpClientFactory to be resolved, it must be registered in the container. Verification was triggered because Container.Options.EnableAutoVerification was enabled. To prevent the container from being verified on first resolve, set Container.Options.EnableAutoVerification to false.

The mentioned class HttpClient in the exception is our internal adapter/helper that handles the connection to IHttpClientFactory and contains some helper methods. All code that wants to do Http calls uses this class (through an interface) instead of IHttpClientFactory directly.

Additional context

Add any other context about the problem here. e.g.:

  • SimpleInjector version 5.3.0
  • SimpleInjector.Integration.ServiceCollection version 5.3.0
  • .NET core v3.1
  • We use the Azure Functions integration (described in the documentation and in a Github issue where it was discussed).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
CasperWSchmidtcommented, Jun 2, 2022

Yeah I know, and I agree 😃 I remember we worked on the integration “together”

1reaction
dotnetjunkiecommented, Jun 2, 2022

Hi Casper,

I’m happy you figured this out. I was starting to expect some weird behavior in the framework. I’m the first to admit, though, that the Azure Functions integration for Simple Injector is a bit clunky and confusing. It tries to work around the limitations in Azure Functions to get the integration done. Hopefully this is something that Microsoft will improve in the future so the integration with Simple Injector can be simplified in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto cross-wiring ASP.NET Core components · Issue #442
I've been playing with it a bit and the issue with @inject in a view was not solved (with of course is logical...
Read more >
NET Core Identity and Simple Injector. Crosswire not working
I am using simple injector (4.8.1) on a project that uses asp.net core identity. I tried to crosswise UserManager but I got an...
Read more >
ServiceCollection Integration Guide
When auto cross wiring is disabled, individual framework components can still be cross wired, using the CrossWire<T> extension method: services.
Read more >
Untitled
Scanned photos not showing up, Clean carpets and more, Emma kivell shane richie jr, ... with cash youtube, Idshs australia, Jackson tempstar wiring...
Read more >
Untitled
Cherry mobile t18 touch screen problem, Fidelino ramirez, Monata rena kdi kanggo ... Kate gummett, Tayas orient strawberry, Adan hernandez boxing, Autocross ......
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