Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Zweben 268 posts 754 karma points
    Aug 12, 2019 @ 14:58
    David Zweben
    0

    Proper way to access services from custom HttpHandler?

    Hello,

    I am working on a custom HttpHandler for our Umbraco 8 website. The handler is working in general, but I need to add a piece to it that requires access to Umbraco's MemberService and MediaService, and I'm confused about how this should be done.

    I updated my handler to inherit from UmbracoHttpHandler, and this looks like it should give it access to the services via Current.Services. When I try to access those object instances directly inside the ProcessRequest method, though, I get an Object reference not set to an instance of an object. error.

    I have also tried injecting the services via LightInject, and it looked like instances were getting injected, but I was still getting a null reference exception on MediaService. I was just specifying the desired dependencies in a constructor, but not registering the code as a component or anything; I wasn't sure if that was needed, or how to do it.

    Can anyone point me in the right direction?

  • David Zweben 268 posts 754 karma points
    Aug 12, 2019 @ 20:47
    David Zweben
    101

    Going to answer my own question here: after reading https://our.umbraco.com/documentation/Reference/Common-Pitfalls/ again, I see that UmbracoHttpHandler is mentioned as one of the base classes that exposes the services, and that the existing instances should be used instead of DI. I am having an issue with that, but I'm going to make a separate thread to avoid confusion.

Please Sign in or register to post replies

Write your reply to:

Draft