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.
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.
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
andMediaService
, 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 viaCurrent.Services
. When I try to access those object instances directly inside the ProcessRequest method, though, I get anObject 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?
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.
is working on a reply...