Closed GoogleCodeExporter closed 8 years ago
Here's a gist that shows how I can get injecting the request now. It works but
it's ugly.
https://gist.github.com/glennblock/906f68420d6bd12d826c
Original comment by glenn.bl...@gmail.com
on 22 Jun 2013 at 8:29
Any reason for the wrapper type in the Gist? Your original example has the
HttpRequestMessage being directly injected.
Original comment by alex.meyergleaves
on 25 Jun 2013 at 1:24
Don't worry, I see now. One is what you would like, and the other is what you
had to do. :)
That is way harder than it should be. The dependency scopes really needed some
more context provided to them Web API.
Original comment by alex.meyergleaves
on 25 Jun 2013 at 1:53
This issue was closed by revision 60d369499963.
Original comment by alex.meyergleaves
on 25 Jun 2013 at 2:50
This one is now ready for the next release. Just call the new
RegisterHttpRequestMessage method on the builder and provide the
HttpConfiguration instance.
builder.RegisterHttpRequestMessage(config);
You can then resolve HttpRequestMessage in your dependencies.
Original comment by alex.meyergleaves
on 25 Jun 2013 at 2:52
Just tested, it works perfectly. Thanks Alex!
Original comment by glenn.bl...@gmail.com
on 27 Aug 2013 at 11:27
i used RegisterHttpRequestMessage(config)
why i get a exception when Resolve<HttpRequestMessage>
Original comment by czcz1024@gmail.com
on 25 Dec 2013 at 9:38
The RegisterHttpRequestMessage adds a DelegatingHandler to the Web API pipeline
that updates the container with the HttpRequestMessage instance of the
executing request. You will not be able to resolve the HttpRequestMessage
outside of a request. When unit testing you can create your own
HttpRequestMessage and pass that in directly or add it to the container if
required.
Original comment by alex.meyergleaves
on 28 Dec 2013 at 3:32
alex,thanks for answer.
i realy resolve inside a request ,but there something more.
in a request,i call an other class,and in this class ,i use common service
locator.
so i config both web api and common service locator;i want fix the
lifetimescope in the delegate ServiceLocator.SetLocatorProvider,so i need
return a new
AutofacServiceLocator(request.GetDependencyScope().GetRequestLifetimeScope());so
i need the request, how can i resolve it
Original comment by czcz1024@gmail.com
on 9 Jan 2014 at 6:37
I don't think this is possible. There just isn't a way to create a static
reference to the current request. Your best bet would be to remove the service
locator and wire everything up properly.
Original comment by alex.meyergleaves
on 19 Jan 2014 at 2:40
Original issue reported on code.google.com by
glenn.bl...@gmail.com
on 22 Jun 2013 at 8:06