This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
How to inject a dependency to NancyModule which itself depends on the Request? #2869
Closed
4 tasks done
Prerequisites
DEBUG
andRELEASE
modeDescription
Sometimes I need to read data from the request itself to initialize a service that a certain
NancyModule
depends on. Take the following example:I would register both like this:
where the class
FromRequestApiKeyProvider
provides the api key by reading data from the request. This is what I need to be able to do:Not being able to do this forces me into initializing a concrete implementation of
Service
inside the request handlers which in turn forbids me from unit-testing my NancyModule.Another scenario where this popped up is where I put data into the
Items
of aNancyContext
in theBefore
pipeline (in Bootstrapper -> ApplicationStartup) and then needing to read the data I put in the NancyContext to initialize some service like the above.As an example for the latter scenario, see the Nancy.Serilog library where you have to get a contexual logger from inside the request handler i.e.
var logger = this.CreateLogger();
where ideally this would be injected as a dependency to the NancyModule at the constructor level.The text was updated successfully, but these errors were encountered: